我为自己制作了一个自定义的 Sublime 语法,用于特定的格式/突出显示,它按预期工作。但是我发现这种语法的行为与其他语法(例如 Markdown)不同,具有换行和自动换行。
必须启用自动换行以获得更好的可读性(因为它不是用于编码,而是更像文档)。
在自定义语法中,单词以换行符分隔,而在 Markdown 中则不然。
我没有找到任何 Sublime 语法或设置的选项(如内容调整)来解决此问题。
这是语法的部分示例:
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: ScriptTest
file_extensions:
- scripttest
scope: source.scripttest
contexts:
main:
- include: comment
- include: string
- include: title
- include: bold
- include: key
- include: number
- include: punct
- include: mark
- include: tag
- include: default
default:
- match: '\p{P}'
scope: text.plain
- match: '\w'
scope: text.plain
punct:
- match: '(\+ |- |= |> |< |-> |<- |=> |<= )'
scope: punctuation
tag:
- match: '@[\w]+'
scope: meta.tag
- match: '\#[\w]+'
scope: meta.tag.hash
[...]
问题的出现是因为在您的
default
上下文中,您一次匹配一个字符。这导致这些字符被 Sublime 视为单独的标记,并且首先在标记的基础上完成自动换行,因此它相信它可以安全地自动换行它们。
解决方案是在一次匹配中匹配整个单词/尽可能多的非格式字符。