Sunday, 27 October 2019

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 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-]+/ should only match till dvc pipeline. How is it exactly functioning?

How does /dvc [a-z-]+ ?/ override it and continues matching the expression?

Please refer to this library docs here: https://highlightjs.readthedocs.io/en/latest/reference.html



from Highlight.js not respecting parent regex of a sub mode

No comments:

Post a Comment