Sublime Text 自定义语法高亮
Sublime Text custom syntax highlighting
我正在研究自定义语法突出显示并从 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
示例文本:
<file bash>
Some bash code block
Some bash code block
</file>
我的代码突出显示了方括号 <>
、file
和 bash
关键字,但我不知道如何为内部的块添加颜色。最终我想把它作为块评论或类似的东西,这样它就会脱颖而出。有什么建议吗?
我需要一个解决方案来避免为没有结束标记的标记添加注释突出显示。例如,我正在使用的标记中有某些不使用结束符的标记,例如没有 </tag>
的 <tag without close>
。有什么方法可以在正则表达式中添加排除项,使其仅在有打开和关闭标签时才起作用,但只有打开标签时不起作用?
<tag without close>
This should not be a comment.
<file bash>
This should be a comment.
</file>
This also should not be a comment.
只有一小部分标签会像上面的 <tag>
那样使用,主要用于元数据。
一种方法,大致基于 interiors of both <style>
and <script>
are managed 的方式,是使用 with_prototype
,它具有 pop
.
- match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.other.html
push:
- match: '(</)()(>)'
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: (?=</)
pop: true
- include: main
- match: '.'
scope: string.quoted.single.html
请注意,这里的 ([a-zA-Z0-9:]+)
匹配任何有效的标签名称,就像您在问题中一样,并且 </code> 用于稍后匹配该组,两者都在立即解耦中 <code>match
条件和 with_prototype
条件。 with_protoype
定义了应用于当前上下文中所有内容的模式,因此我们在这里使用它来确保我们 pop
在我们达到 </file>
时以注释式突出显示,而不是被视为评论的一部分。
在 with_prototype
中,- include: main
语句确保您的评论类内容中的任何标签都像外部 <file>
标签一样工作。例如,下面的 <hello>
与 <file>
.
的作用相同
<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
如果这早于 match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
行,任何 <hello>
标签都不会调用注释式突出显示。
此文本不是 comment.block.html。
一些 bash 代码块
一些 bash 代码块
一些 bash 代码块
我正在研究自定义语法突出显示并从 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
示例文本:
<file bash>
Some bash code block
Some bash code block
</file>
我的代码突出显示了方括号 <>
、file
和 bash
关键字,但我不知道如何为内部的块添加颜色。最终我想把它作为块评论或类似的东西,这样它就会脱颖而出。有什么建议吗?
我需要一个解决方案来避免为没有结束标记的标记添加注释突出显示。例如,我正在使用的标记中有某些不使用结束符的标记,例如没有 </tag>
的 <tag without close>
。有什么方法可以在正则表达式中添加排除项,使其仅在有打开和关闭标签时才起作用,但只有打开标签时不起作用?
<tag without close>
This should not be a comment.
<file bash>
This should be a comment.
</file>
This also should not be a comment.
只有一小部分标签会像上面的 <tag>
那样使用,主要用于元数据。
一种方法,大致基于 interiors of both <style>
and <script>
are managed 的方式,是使用 with_prototype
,它具有 pop
.
- match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.other.html
push:
- match: '(</)()(>)'
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: (?=</)
pop: true
- include: main
- match: '.'
scope: string.quoted.single.html
请注意,这里的 ([a-zA-Z0-9:]+)
匹配任何有效的标签名称,就像您在问题中一样,并且 </code> 用于稍后匹配该组,两者都在立即解耦中 <code>match
条件和 with_prototype
条件。 with_protoype
定义了应用于当前上下文中所有内容的模式,因此我们在这里使用它来确保我们 pop
在我们达到 </file>
时以注释式突出显示,而不是被视为评论的一部分。
在 with_prototype
中,- include: main
语句确保您的评论类内容中的任何标签都像外部 <file>
标签一样工作。例如,下面的 <hello>
与 <file>
.
<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
如果这早于 match: '(?:^\s+)?(<)([a-zA-Z0-9:]+)\b(?![^>]*/>)'
行,任何 <hello>
标签都不会调用注释式突出显示。
此文本不是 comment.block.html。 一些 bash 代码块 一些 bash 代码块 一些 bash 代码块