Last line not getting tokenized after upgrade of highlight.js
See original GitHub issueDescribe the issue/behavior that seems buggy
The last line of code does not get highlighted correctly. The issue persists in at least Java and Python, I suspect the issue will appear in any code. I suspect the API has changed since the code I’m working with was written.
Sample Code or Instructions to Reproduce
let tokenized = hljs.highlight(codeContent, {language}).value;
this.note = this.note.replace('{content}', '<pre>' + tokenized + '</pre>');
The end of note later looks like this:
<span class="hljs-built_in">print</span>(<span class="hljs-string">"Hallo Welt"</span>)
x = <span class="hljs-built_in">input</span>(<span class="hljs-string">"Mach mal"</span>)
doSomething()
</pre></body></html>
With everything except the last line being formatted.
Expected behavior
The last line should be parsed into at least one span. Additional context
I am updating a typescript program which used highlight.js 9.10.0 before and now uses 11.6.0. I looked in the breaking changes but could not figure out what was going wrong.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Discuss: Custom token callbacks, or mode value property ...
Hello, i'm playing around with highlight.js (9.2.0) and want to integrate with a -grammar add-on (following previous work on syntax-highlighting, ...
Read more >How to tokenize a code snippet using a Textmate grammar in ...
I've tried Highlight.js and Prism, but neither of them tokenize the code correctly (it's Ruby), so in the end the code is not...
Read more >highlight.js demo
... --heading-1: 30px/32px Helvetica, sans-serif; } @import url(print.css); @media print { a[href^=http]::after { content: attr(href) } } ...
Read more >Goodbye, Prettify. Hello highlight.js! Swapping out our Syntax ...
I'm not sure I can update the website itself (I'll ask - it's still managed by the original author), but I've updated the...
Read more >Syntax Highlight Guide | Visual Studio Code Extension API
There are two components to syntax highlighting: Tokenization: Breaking text into a list of tokens. Theming: Using themes or user settings to map...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This actually worked perfectly, thank you for the answer and the advice.
I’m not sure why you wouldn’t just style the parent element with the “base style”… styling every single line is just creating this problem.