highlightjs / highlightjs/highlight.js
(bash) regression: “TODO” in comments no longer highlighted
- Dominant language
- JavaScript
- Stars
- 25k
- Forks
- 3.8k
- Avg merge
- 11h 35m
- Merged PRs (30d)
- 3
Description
**Describe the issue**
```bash
# 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 d78749a59410387f7232beb296e4606c9f4b7d08 (#3918).
**Which language seems to have the issue?**
bash
**Are you using `highlight` or `highlightAuto`?**
highlight
**Sample Code to Reproduce**
```bash
# 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 d78749a59410387f7232beb296e4606c9f4b7d08 (#3918); in particular the relevant problem seems to be somewhere in this code:
https://github.com/highlightjs/highlight.js/blob/85b20421a2620b765508f16289e0592e0563cfcb/src/languages/bash.js#L41-L52
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
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 @@
echo asdf#qwert yuiop
echo asdf #qwert yuiop
+
+# TODO: this *is* a comment
```
Contributor guide
Assessment
This issue has not been assessed yet.