markdown-it-highlightjs
markdown-it-highlightjs copied to clipboard
Only the first codeblock is has hljs class added to it
Typical highlightjs output has the structure
<pre>
<code>
</code>
</pre>
This extension adds the 'hljs' class to the code tags using the wrapCodeRenderer.
There's nothing stopping you from having multiple code blocks inside the <pre>
tags. It's a bit odd, but I did it recently to overlay a SVG on top of some hex. In this case, hljs is only added to the first block, and this means the second code block doesn't receive the same styles.
This can be fixed by changing
return function wrappedRenderer (...args) {
return renderer(...args)
.replace('<code class="', '<code class="hljs ')
.replace('<code>', '<code class="hljs">')
}
to
return function wrappedRenderer (...args) {
return renderer(...args)
.replaceAll('<code class="', '<code class="hljs ')
.replaceAll('<code>', '<code class="hljs">')
}