You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this specific case, highlightjs shouldn't treat enable as a keyword. More generally, when parsing shell scripts, I believe that - should be considered a "word character".
I'm aware from reading previous issues that when this comes up there's hesitance to try to do much with the bash parsing unless someone is ready to write a real parser. But I think hyphenate commands and options are a common case. Even if there are cases this might start to fail on which worked before (I can't think of any, but maybe that's my limited imagination), they're probably much more exotic than --set-foo, --enable-bar, and, cmd-case-while-blahblahblah.
Additional context
I'm okay with the idea of highlightjs closing out this issue if it's just too much the same as its predecessors.
If backwards compatibility is a major concern, perhaps this could be an option which is set by the user somehow? hljs.SetParserOption("shell", "hyphens-are-wordchars")? (I have very little notion of how highlightjs works on the inside and how configurable the parsers are or ought to be by design.)
The text was updated successfully, but these errors were encountered:
I'd be open to a patch with a few tests that changes the keyword $pattern to include "-" which I think would resolve this for most common cases... and we'll see if it conflicts with any existing tests or edge cases.
It looks like perhaps we already do this for "." and "_"... since none of our keywords have . or _ in them.
In bash, option, param, and command names may contain builtins as
hyphen-delimited components. As in `foo --set-bar`.
In order to handle this, just add `-` to the pattern's set of word
characters. Includes a new test for bash tokens containing keywords,
which checks hyphens and underscores for a few common cases.
resolveshighlightjs#2668
sirosen
added a commit
to sirosen/highlight.js
that referenced
this issue
Sep 1, 2020
In bash, option, param, and command names may contain builtins as
hyphen-delimited components. As in `foo --set-bar`.
In order to handle this, just add `-` to the pattern's set of word
characters. Includes a new test for bash tokens containing keywords,
which checks hyphens and underscores for a few common cases.
Against current `master`, the new test fails, which helps to confirm
the fix.
resolveshighlightjs#2668
Describe the issue
I've run into a case similar to #1740 and other issues. In my case, we had
--enable-foo
on our site, and highlightjs thinks thatenable
is a keyword.Sample Code to Reproduce
minimal full reproduction
Expected behavior
In this specific case, highlightjs shouldn't treat
enable
as a keyword. More generally, when parsing shell scripts, I believe that-
should be considered a "word character".I'm aware from reading previous issues that when this comes up there's hesitance to try to do much with the bash parsing unless someone is ready to write a real parser. But I think hyphenate commands and options are a common case. Even if there are cases this might start to fail on which worked before (I can't think of any, but maybe that's my limited imagination), they're probably much more exotic than
--set-foo
,--enable-bar
, and,cmd-case-while-blahblahblah
.Additional context
I'm okay with the idea of highlightjs closing out this issue if it's just too much the same as its predecessors.
If backwards compatibility is a major concern, perhaps this could be an option which is set by the user somehow?
hljs.SetParserOption("shell", "hyphens-are-wordchars")
? (I have very little notion of how highlightjs works on the inside and how configurable the parsers are or ought to be by design.)The text was updated successfully, but these errors were encountered: