Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the first codeblock is has hljs class added to it #33

Closed
danishcake opened this issue Sep 18, 2024 · 1 comment · Fixed by #34
Closed

Only the first codeblock is has hljs class added to it #33

danishcake opened this issue Sep 18, 2024 · 1 comment · Fixed by #34

Comments

@danishcake
Copy link

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">')
  }
@danishcake
Copy link
Author

This project targets an older version of Javascript, so we'll get type errors from this. Instead, use a regex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant