fix(bash): Add consistent highlighting for command-line options#4421
fix(bash): Add consistent highlighting for command-line options#4421WaterXiao-git wants to merge 1 commit into
Conversation
Add an OPTION mode to match short (-o) and long (--option=value) command-line flags, ensuring they are highlighted consistently across continuation lines instead of being partially matched by keyword or path patterns. Closes highlightjs#4288
| // to ensure consistent highlighting across continuation lines. | ||
| const OPTION = { | ||
| className: 'attr', | ||
| begin: /(?:^|\s)--?\w[\w-]*(?:=?\S*)?\s*/, |
There was a problem hiding this comment.
I'm not so sure about flags like
--mode=compact
Think perhaps the = should be operator (or nothing) and maybe compact should be a string? Thoughts?
Might be nice to see this a few different ways. CC @allejo Any thoughts?
arturict
left a comment
There was a problem hiding this comment.
I reproduced the current matcher against shell separators and redirections. There is a correctness issue beyond the open =value scoping question: (?:=?\S*)? is broader than an optional =value because = itself is optional.
For example, the mode consumes --foo;, --foo|grep, and --foo>out, which would hide shell operators/redirections inside hljs-attr; the surrounding whitespace is scoped too. Please scope only the option token and let the existing modes parse the remainder. A multi-part match could preserve the leading boundary without assigning it the attr scope.
This grammar change also needs markup cases for --mode=compact, --foo | grep, --foo>out, quoted/variable values, and short options. Since #4376, #4367, and #4369 address the same issue, it may be worth consolidating around one tested approach.
|
Agree, more works and tests needed here. |
|
If this option highlighting change touches multiple grammars, maybe include a compact list of tested languages to reduce regression risk. |
|
Embedding is typically just running the grammar on a subset of code, so any tests added here would also apply to anywhere this grammar is embedded in another grammar... but it does seem we need a beefier chunk of tests here and then try to come up with the minimal regex that will cover our test cases. And false positive cases. Keep piling on the false positive cases anyone. |
Add an OPTION mode to match short (-o) and long (--option=value) command-line flags, ensuring they are highlighted consistently across continuation lines instead of being partially matched by keyword or path patterns.
Closes #4288