Highlight.js: JavaScript single line comments.

Created on 14 Aug 2015  路  4Comments  路  Source: highlightjs/highlight.js

Single line comments in Javascript are not terminated at end of line. Everything after // is formatted as a comment regardless of subsequent line breaks. See the attached image showing the incorrect output.

screen shot 2015-08-14 at 2 58 39 pm

screen shot 2015-08-14 at 3 02 39 pm

In the off chance it makes a difference, I'm calling hljs manually: hljs.highlightBlock(codeTag);

Most helpful comment

With the screenshots alone, I'm assuming you didn't configure highlight.js to expect <br>s rather than line breaks. You need to call hljs.configure({ useBR: true }) before hljs.highlightBlock(codeTag) and see if that fixes you single line comment issue.

All 4 comments

I haven't dug super deeply into this yet, but I did play with changing the end pattern. ex. hljs.CLCM.e = "a";, and it still never finds an end for the line comment. I compared against the block comment object CLBM, and can't see any obvious differences that would account for one working but the other not, but can't see anything obvious.

With the screenshots alone, I'm assuming you didn't configure highlight.js to expect <br>s rather than line breaks. You need to call hljs.configure({ useBR: true }) before hljs.highlightBlock(codeTag) and see if that fixes you single line comment issue.

That did it. Apologies for the noise.

Great, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

zhouxy666 picture zhouxy666  路  3Comments

Lestoroer picture Lestoroer  路  7Comments

niche4u picture niche4u  路  5Comments

Suyash2810 picture Suyash2810  路  8Comments