Skip to content

Issue: CR/LF line-breaks can introduce extra line breaks during highlighting #3298

Open
@deniskovalchuk

Description

Workaround

This is a known issue and being discussed (see below). If you run into this the correct solution is to normalize your content to only \n line breaks BEFORE highlighting.


Describe the issue
Extra line breaks are added to comments if your DOS code uses Windows-style
line endings (CRLF). The problem is not reproduced if Unix-style line endings
are used (LF).

I'm not aware of the internal details of highlight.js, but I can assume a
problem with using \s in the COMMENT regular expression.

/^\s*@?rem\b/, /$/,

Which language seems to have the issue?
DOS

Are you using highlight or highlightAuto?
highlightElement

Sample Code to Reproduce
Run the samples below and see console output.

Windows-style line endings (bad):
https://jsfiddle.net/ua3om8fb/1/

Unix-style line endings (good):
https://jsfiddle.net/8xw4vq39/3/

Expected behavior
expected

<span class="hljs-comment">rem line1</span>
<span class="hljs-comment">rem line2</span>

Actual behavior
actual

<span class="hljs-comment">rem line1</span>
<span class="hljs-comment">
rem line2</span>

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions