0

Ok so by the following yaml definition, shouldn't only what's in between {blah} and {!blah} get text.html.basic syntax highlighting? And the {blah} tags themselves take the highlighting of a comment? Unfortunately it's not happening that way. HTML highlighting is anywhere in the document, and {blah} doesn't get comment highlighting.

# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Test
scopeName: source.test
fileTypes: [test]
uuid: 3631aac6-ee25-4ec1-ab08-39f156235363

patterns:
  - name: comment.number-sign
  begin: \{blah\}
  end: \{\!blah\}
  patterns:
  - include: text.html.basic
  match: .
...

Sample Code:

{blah}
<input type="text"/>
{!blah}              <----- these are not styled according to comment.number-sign
<input type="text"/> <----- this also has HTML highlighting and I don't want it to
citizen conn
  • 15,300
  • 3
  • 58
  • 80

1 Answers1

1

This should get you started:

# [PackageDev] target_format: plist, ext: tmLanguage
name: Test
scopeName: source.test
fileTypes: [test]
uuid: 3631aac6-ee25-4ec1-ab08-39f156235363

patterns:
- name: html.test
  begin: (\{blah\})
  beginCaptures:
    '1': {name: comment.blah.test}
  end: (\{!blah\})
  endCaptures:
    '1': {name: comment.blah.test}
  patterns:
  - include: text.html.basic

The name is the base scope for the entire selector. beginCaptures and endCaptures assign the comment.blah.test scope to the {blah} tags, while the include rule assigns HTML highlighting to whatever is between the begin and end tags.

Using the Neon Color Scheme (full disclosure: I'm its maintainer), a sample file looks like this:

foo.test

As you can see, {blah} and {!blah} are in gray italics, the comment scope. Markup outside the {blah} tags is not highlighted at all, while that enclosed in the {blah} tags is highlighted as HTML.

For more on syntax definitions, check the tutorial and the reference at the unofficial docs.

MattDMo
  • 100,794
  • 21
  • 241
  • 231