Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bash) regression: “TODO” in comments no longer highlighted #4234

Open
wolfgang42 opened this issue Mar 31, 2025 · 1 comment · May be fixed by #4239
Open

(bash) regression: “TODO” in comments no longer highlighted #4234

wolfgang42 opened this issue Mar 31, 2025 · 1 comment · May be fixed by #4239
Labels
bug help welcome Could use help from community language

Comments

@wolfgang42
Copy link

wolfgang42 commented Mar 31, 2025

Describe the issue

# This is a comment with a TODO item in it

should have the TODO highlighted as scope doctag, and used to, but no longer does as of d78749a (#3918).

Which language seems to have the issue?
bash

Are you using highlight or highlightAuto?
highlight

Sample Code to Reproduce

# This is a comment with a TODO item in it

Expected behavior
TODO is highlighted as doctag scope.

Additional context
I upgraded highlight.js and this stopped working. I bisected the problem to d78749a (#3918); in particular the relevant problem seems to be somewhere in this code:

const COMMENT = hljs.inherit(
hljs.COMMENT(),
{
match: [
/(^|\s)/,
/#.*$/
],
scope: {
2: 'comment'
}
}
);

As far as I can tell, the scope: {2: 'comment'} is somehow screwing up the mode.contains.push({scope: 'doctag', ...}) detection in modes.js, but I don’t have a good enough grasp on highlight.js internals to really understand what's going on or how to fix it.

Test case which I expect to pass:

diff --git a/test/markup/bash/not-comments.txt b/test/markup/bash/not-comments.txt
--- a/test/markup/bash/not-comments.txt
+++ b/test/markup/bash/not-comments.txt
@@ -1,3 +1,5 @@
 echo asdf#qwert yuiop
 
 echo asdf #qwert yuiop
+
+# TODO: this *is* a comment
diff --git a/test/markup/bash/not-comments.expect.txt b/test/markup/bash/not-comments.expect.txt
index ab128642..0f57ee8b 100644
--- a/test/markup/bash/not-comments.expect.txt
+++ b/test/markup/bash/not-comments.expect.txt
@@ -1,3 +1,5 @@
 <span class="hljs-built_in">echo</span> asdf#qwert yuiop
 
 <span class="hljs-built_in">echo</span> asdf <span class="hljs-comment">#qwert yuiop</span>
+
+<span class="hljs-comment"># <span class="hljs-docstring">TODO:</span> this *is* a comment</span>
@wolfgang42 wolfgang42 added bug help welcome Could use help from community language labels Mar 31, 2025
@wolfgang42
Copy link
Author

(CC @iFreilicht and @joshgoebel as author/reviewer of previous PR.)

wolfgang42 added a commit to wolfgang42/highlight.js that referenced this issue Apr 10, 2025
wolfgang42 added a commit to wolfgang42/highlight.js that referenced this issue Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant