highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.6k stars 3.58k forks source link

False positives for comments in bash #3917

Closed iFreilicht closed 11 months ago

iFreilicht commented 11 months ago

Describe the issue

Which language seems to have the issue? bash

Sample Code to Reproduce

$ echo asdf#qwert
asdf#qwert
# compared to
$ echo asdf #qwert
asdf

You can see that github's highlighter gets it right, but hljs wraps everything following # in a comment span:

<span class="hljs-comment">#qwert</span>

This is incorrect according to POSIX 2.3 "Token Recognition" (see rules 8 and 9 in particular), and from my testing sh, bash and zsh are consistent with this.

Expected behavior If there is no space or start-of-line in front of a #, it should not start a comment span.

Additional context I'm working on a fix for this myself right now, will submit a PR in a bit. EDIT: PR is ready, see link below.