highlightjs / highlightjs/highlight.js

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

Open
#4,229 3 comments 0 reactions 0 assignees View on GitHub
bug help welcome language
Dominant language
JavaScript
Stars
25k
Forks
3.8k
Avg merge
11h 35m
Merged PRs (30d)
3

Description

**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**
```typescript
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](https://github.com/aws/mynah-ui) repository for AWS, specifically in the [SyntaxHighlighter](https://github.com/aws/mynah-ui/blob/main/src/components/syntax-highlighter.ts) component.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.