我正在开发一个自定义语法高亮功能,并从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 without close>
,它没有</tag>
。是否有任何方法在正则表达式中添加排除条件,只在有开放和关闭标记时起作用,而当只有开放标记时不起作用?<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>
一样使用,主要用于元数据。
<标签中的某些文本>
,另一种情况是<标签开头>块引用文本</标签结尾>
。 - user1781482