我正在编写一个 .tmLanguage 文件来突出显示降价文件(.md),并且降价文件中有一些 cpp 代码。我想使用 c++.tmLanguage(在 Packages\C++ 中)来解决语法问题。我该怎么做?
问问题
797 次
1 回答
2
学习如何编写语言定义的最好方法是查看现有的定义。包控制中有很多现有的 Markdown 语法定义,所以我建议您仔细查看它们以了解事物的结构。
假设您使用的是PackageDev
's.YAML-tmLanguage
格式,防护代码的存储库将如下所示:
repository:
fenced-c:
name: markup.raw.block.markdown markup.raw.block.fenced.markdown
begin: (\s*```)\s*(c)\s*$
end: (\1)\n
captures:
'1': {name: punctuation.definition.fenced.markdown}
'2': {name: variable.language.fenced.markdown}
patterns:
- include: source.c
fenced-c++:
name: markup.raw.block.markdown markup.raw.block.fenced.markdown
begin: (\s*```)\s*(c\+\+)\s*$
end: (\1)\n
captures:
'1': {name: punctuation.definition.fenced.markdown}
'2': {name: variable.language.fenced.markdown}
patterns:
- include: source.c++
fenced-coffee:
name: markup.raw.block.markdown markup.raw.block.fenced.markdown
begin: (\s*```)\s*(coffee)\s*$
end: (\1)\n
captures:
'1': {name: punctuation.definition.fenced.markdown}
'2': {name: variable.language.fenced.markdown}
patterns:
- include: source.coffee
# etc.
使用内置转换工具转换为 XML,如下所示:
<key>repository</key>
<dict>
<key>fenced-c</key>
<dict>
<key>begin</key>
<string>(\s*```)\s*(c)\s*$</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.fenced.markdown</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.language.fenced.markdown</string>
</dict>
</dict>
<key>end</key>
<string>(\1)\n</string>
<key>name</key>
<string>markup.raw.block.markdown markup.raw.block.fenced.markdown</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.c</string>
</dict>
</array>
</dict>
<key>fenced-c++</key>
<dict>
<key>begin</key>
<string>(\s*```)\s*(c\+\+)\s*$</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.fenced.markdown</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.language.fenced.markdown</string>
</dict>
</dict>
<key>end</key>
<string>(\1)\n</string>
<key>name</key>
<string>markup.raw.block.markdown markup.raw.block.fenced.markdown</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.c++</string>
</dict>
</array>
</dict>
<key>fenced-coffee</key>
<dict>
<key>begin</key>
<string>(\s*```)\s*(coffee)\s*$</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.fenced.markdown</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>variable.language.fenced.markdown</string>
</dict>
</dict>
<key>end</key>
<string>(\1)\n</string>
<key>name</key>
<string>markup.raw.block.markdown markup.raw.block.fenced.markdown</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.coffee</string>
</dict>
</array>
</dict>
<!-- and so on... -->
我强烈建议您使用,因为PackageDev
YAML比 XML 更容易使用。或者,您可以使用新的基于 YAML 的格式,但目前仅在 Sublime Text 3开发版本3084 及更高版本中支持,这意味着您需要成为注册用户才能访问它。我建议现在坚持,直到发布支持新格式的新公共版本。.sublime-syntax
.YAML-tmLanguage
您可以在PackageDev
Github存储库中查找更多文件示例.YAML-tmLanguage
。此外,我是该项目的首席开发人员,您也可以在 Github 上Python Improved
找到我的所有源文件。
于 2016-01-05T19:40:04.693 回答