Open khumam opened 6 days ago
Hey @khumam. Is there are reason you aren't following highlightjs' recommendation to use <pre><code>
? I'm also confused how the parentElement could be null
. Worst case, parentElement would be the page body. Are you creating the codeblock at runtime using something like document.createElement?
I'm hesitant to always wrap the codeblock in a div because this could break some implementations. Ideally, this add-on wouldn't add any extra DOM elements. The parent check seems like a working solution, but I want to understand how you got into this edge case first :D
I have the article form with a text editor, and I noticed that the code is inlined with other paragraphs, like this:
When I used
highlightjs-copy
on my article's read page, it returned an error because the plugin attempted to do the following:Sometimes, the button appears on top of the article's parent, not inside the
<pre>
code block. However, the issue was resolved by manually adding a wrapper before calling the plugin:I think it would be better if we add a handler or condition to check if
el.parentElement
is null and then add the parent manually to prevent this error. Maybe something like this: