highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(java) Code not getting tokenized (and thus not highlighted)

Open Jurredr opened this issue 8 months ago • 3 comments

Describe the issue

Which language seems to have the issue? Java. It works perfectly fine for any other language we've tested with. Just Java seems to break for some reason, with multiple different code examples tested.

Are you using highlight or highlightAuto? Highlighting it through hljs.highlightElement(codeElement); where codeElement is an HTML element of type code, and then rendering that HTML element to the DOM.

Sample Code to Reproduce

const codeElement = DomBuilder.getInstance().build({
  type: 'code',
  classNames: [
    ...(props.language !== undefined ? [ `language-${props.language}` ] : [ 'language-plaintext' ])
  ],
  innerHTML: "Some code string here"
});
hljs.highlightElement(codeElement);
Image

Expected behavior The code is tokenized into spans and highlighted accordingly.

Additional context

This issue is occurring in the open source MynahUI repository for AWS, specifically in the SyntaxHighlighter component.

Jurredr avatar Mar 20 '25 14:03 Jurredr

  • Have you absolutely, for certain loaded/bundled the java grammar?
  • Are there any errors in the console?

joshgoebel avatar Mar 22 '25 18:03 joshgoebel

  • I haven't specified any specific languages / grammars, but let me see if it it bundled
  • No errors in console

Jurredr avatar Mar 25 '25 16:03 Jurredr

If you can reproduce with a jsfiddle or similar I can take a look... right now best guess is you haven't built in java.

joshgoebel avatar Apr 23 '25 02:04 joshgoebel