Highlightjs not respecting parent regex of a sub mode
See original GitHub issueI need to write a lexer which highlights my command-line tool commands properly.
$ dvc add file.csv
$ dvc pipeline list
So the command starts with dvc
and it may have one or two subcommands - add
or pipeline list
respectively.
Therefore, it should highlight dvc add
and dvc pipeline list
in first and second case respectively.
contains: [
{
begin: /^\s*\$\s(dvc|git) [a-z-]+/,
returnBegin: true,
contains: [
{
begin: /dvc [a-z-]+ ?/,
lexemes: '[a-z-]+',
keywords: {
built_in:
'dvc'
},
contains: [
{
begin: /\w+(?![\S])/,
keywords: {
built_in: 'list'
}
}
],
className: 'strong'
}
]
}
]
It matches $ dvc pipeline list
even though the parent regex i.e. /^\s*\$\s(dvc|git) [a-z-]+/
and should only match till $ dvc pipeline
. How is it exactly functioning?
How does /dvc [a-z-]+ ?/
override it and continues matching the expression?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:36 (22 by maintainers)
Top Results From Across the Web
Highlight.js not respecting parent regex of a sub mode
I need to write a lexer which highlights my command-line tool commands properly. $ dvc add file.csv $ dvc pipeline list. So the...
Read more >Mode Reference — highlight.js 11.7.0 documentation
This is used when beginning of a sub-mode is a complex expression that should not only be found within a parent mode but...
Read more >highlight.js demo
HTML, XML. <!DOCTYPE html> <title>Title</title> <style>body {width: 500px;}</style> <script type="application/javascript"> function $init() ...
Read more >Highlightjs - Syntax Highlighting your Blog with highlight.js by ...
This is used when beginning of a sub-mode is a complex expression that should not only be found within a parent mode but...
Read more >The "Code Language" selection on the tag wiki page isn't in ...
The community maintains a list of supported languages by inspecting the Highlight.js code file served by Stack Exchange: What is syntax ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Added: https://github.com/highlightjs/highlight.js/pull/2242
Closing this as asked and answered, though conversation can continue if you have any other questions.
Or a different sub-mode for EVERY command… really at this point you’d probably want to write code to build your syntax, not write it by hand…