question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlightjs not respecting parent regex of a sub mode

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:36 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
joshgoebelcommented, Oct 30, 2019

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.

2reactions
joshgoebelcommented, Oct 30, 2019

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…

language_rules = []
language_rules.push(add_command("dvc add"))
language_rules.push(add_command("dvc pipeline", keywords: {...}))

return {
 contains: language_rules
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found