Sublimetext3 升华文本自定义语法高亮显示

Sublimetext3 升华文本自定义语法高亮显示,sublimetext3,sublimetext,sublime-text-plugin,Sublimetext3,Sublimetext,Sublime Text Plugin,我正在做一个自定义语法高亮显示,并从HTML语法中复制了一些片段,因为这篇文章非常相似。我一直在试图找出如何突出显示标记内部的文本。以下是我的定义: - match: "(</?)([a-zA-Z0-9:]+)" captures: 1: punctuation.definition.tag.begin.html 2: entity.name.tag.other.html push: - meta_scope: meta.tag.other.html

我正在做一个自定义语法高亮显示,并从HTML语法中复制了一些片段,因为这篇文章非常相似。我一直在试图找出如何突出显示标记内部的文本。以下是我的定义:

- match: "(</?)([a-zA-Z0-9:]+)"
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.other.html
  push:
    - meta_scope: meta.tag.other.html
    - match: '>'
      scope: punctuation.definition.tag.end.html
      pop: true
    - match: '.'
      scope: string.quoted.single.html

只有一小部分的标记会被使用,如上面的
,主要用于元数据。

一种方法,大致取决于如何使用,就是将
与带有
pop
的原型一起使用

- match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.other.html
  push:
    - match: '(</)(\2)(>)'
      captures:
        1: punctuation.definition.tag.begin.html
        2: entity.name.tag.other.html
        3: punctuation.definition.tag.end.html
      pop: true
    - match: '>'
      scope: punctuation.definition.tag.end.html
      push:
        - match: '.'
          scope: comment.block.html
      with_prototype:
        - match: (?=</\2)
          pop: true
        - include: main
    - match: '.'
      scope: string.quoted.single.html

如果您的标记没有匹配的结束标记,则可以通过为堆栈更高的标记定义特定行为来覆盖此行为,如下所示:

- match: '(?:^\s+)?(<)(hello)\b(?![^>]*/>)'
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.other.html
  push:
    - match: '>'
      scope: punctuation.definition.tag.end.html
      pop: true
    - match: '.'
      scope: string.quoted.single.html
-匹配:'(?:^\s+)(]*/>)
捕获:
1:标点符号.definition.tag.begin.html
2:entity.name.tag.other.html
推送:
-匹配:'>'
范围:标点符号.definition.tag.end.html
波普:没错
-匹配:'.'
范围:string.quoted.single.html
如果这比
匹配:'(?:^\s+(]*/>)行早,则任何
标记都不会调用注释

此文本不是comment.block.html。 一些bash代码块 一些bash代码块 一些bash代码块

哇,这真是太棒了,比我要找的东西先进多了!也感谢你的解释,它有助于学习。这段代码在99%的情况下都非常有效,除非没有结束标记。在什么情况下,您希望突出显示一个块,就像它是一条注释而没有结束标记一样@USER1781482我猜这个想法是将打开和关闭标记之间的任何内容作为块进行威胁。如果只有开放标签,但没有关闭标签,那么就不会有任何块。也许应该将其分为两个单独的部分,以避免过于复杂。因此,一种情况是突出显示
,另一种情况是
块引号文本
@user1781482我不确定这是否可能,同时对所有标记保持开放,但如果只有某些标记会有注释,比如说它是
文件
,您可以始终使用类似
(文件|秩)的内容
替换第一个
匹配中的
([a-zA-Z0-9:]+)
- match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.other.html
  push:
    - match: '(</)(\2)(>)'
      captures:
        1: punctuation.definition.tag.begin.html
        2: entity.name.tag.other.html
        3: punctuation.definition.tag.end.html
      pop: true
    - match: '>'
      scope: punctuation.definition.tag.end.html
      push:
        - match: '.'
          scope: comment.block.html
      with_prototype:
        - match: (?=</\2)
          pop: true
        - include: main
    - match: '.'
      scope: string.quoted.single.html
<file bash>
Some bash code block
<hello stuff>
Some bash code block
</hello>
Some bash code block
</file>
- match: '(?:^\s+)?(<)(hello)\b(?![^>]*/>)'
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.other.html
  push:
    - match: '>'
      scope: punctuation.definition.tag.end.html
      pop: true
    - match: '.'
      scope: string.quoted.single.html