question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Last line not getting tokenized after upgrade of highlight.js

See original GitHub issue

Describe 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">&quot;Hallo Welt&quot;</span>)
x = <span class="hljs-built_in">input</span>(<span class="hljs-string">&quot;Mach mal&quot;</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:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
BWotkacommented, Sep 15, 2022

This actually worked perfectly, thank you for the answer and the advice.

0reactions
joshgoebelcommented, Sep 15, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found