Skip to content

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

Description

@wolfgang42

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>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions