sublimetext 3中具有.sublime-syntax文件类型的多种语法突出显示 [英] multiple syntax highlighting in sublimetext 3 with .sublime-syntax file type
问题描述
我正在使用zk框架,我需要创建一个以XML语法突出显示的sublime语法文件,但是在zscript代码段中使用Java语法突出显示,而在样式上下文中使用CSS语法. 这是zk代码的示例:
I'm using zk framework and I need to do a sublime-syntax file that highlights in XML syntax, but in the zscript snippet uses java syntax highlighting and in style context uses CSS syntax. This is an example of zk code:
<zk>
<style>
.myClass{
width=300px;
}
</style>
<div id="panel1" class="myClass" visible="true" >
<hlayout width="100px">
<image id="icon1" src="/Desktop/image1.png" width="32px"></image>
<image id="icon2" src="/Desktop/image1.png" width="50px"></image>
</hlayout>
</div>
<zscript><![CDATA[
try{
if (panel1.isVisible()) {
//do something
}
}catch(Exception e){
//catch exception
}
]]></zscript>
</zk>
我看到最近发生了一些变化,目前在线的解决方案还不太清楚,例如,在
I saw that some things have been changed recently and the current solutions that are on-line are not very clear, for example at this link I found the following note:
从Sublime Text Build 3084开始,一种新的语法定义格式已经被使用. 添加了.sublime-syntax扩展名.
As of Sublime Text Build 3084, a new syntax definition format has been added, with the .sublime-syntax extension.
强烈建议您使用旧格式 除非与旧版本兼容,否则将在本文档中进行介绍 是理想的.
It is highly encouraged to be used in favor of the legacy format described in this document, unless compatibility with older versions is desired.
可在此处找到文档: http://www.sublimetext.com/docs/3/syntax.html
Documentation is available here: http://www.sublimetext.com/docs/3/syntax.html
因此,我需要一些类似的教程,以了解如何使用SublimeText3构建新的多重语法文件.
So I need something like a tutorial on how to build a new multiple syntax file with SublimeText3.
推荐答案
好,我通过安装 PackageDev (Ctrl
+ Shift
+ P
,选择Package Control: Install Package
,键入并选择PackageDev
以进行安装),然后选择:Tools
-> Packages
-> Package Developement
-> New Syntax Definition
.
ok I solved my problem by installing PackageDev (Ctrl
+Shift
+P
, select Package Control: Install Package
, type and select PackageDev
in order to install it), then I've selected: Tools
-> Packages
-> Package Developement
-> New Syntax Definition
.
我在这里编写了这段代码:
Here I wrote this code:
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: zul
file_extensions:
- zul
scope: text.zul
contexts:
main:
- match: ""
push: "Packages/XML/XML.sublime-syntax"
with_prototype:
- match: '< *zscript *>'
push: Packages/Java/Java.sublime-syntax
with_prototype:
- match: '(?=</ *zscript *>)'
pop: true
- match: '< *script *>'
push: Packages/JavaScript/JavaScript.sublime-syntax
with_prototype:
- match: '(?=</ *script *>)'
pop: true
- match: '< *style *>'
push: Packages/CSS/CSS.sublime-syntax
with_prototype:
- match: '(?=</ *style *>)'
pop: true
-
File_extensions
是使用此语法的扩展列表, -
scope
是source
(用于编程语言),text
是用于标记以及其他所有内容. -
match
是传递给push
元素的正则表达式. -
with_prototype
类似于语法突出显示中的异常,您可以在其中为不同的上下文定义具有不同语法的代码段 File_extensions
is a list of extensions that uses this syntax,scope
issource
for programming languages andtext
for markup and everything else.- The
match
is the regular expression passed to thepush
element. with_prototype
is something like an exception in the syntax highlighting where you can define a snippet with a different syntax for different contexts
此示例通常使用 xml 语法,在标签<zscript> ... </zscript>
之间使用 java 语法突出显示,而在<style> ... </style>
上下文中使用 css 语法.
This example uses generally the xml syntax, between the tag <zscript> ... </zscript>
uses the java syntax highlighting and in the <style> ... </style>
context uses the css syntax.
我将此文件保存在C:\Users\username\AppData\Roaming\Sublime Text 3\Packages\User
中,然后在View
-> Syntax
-> User
-> zul
(文件名)中创建了此语法文件.
I saved this file in C:\Users\username\AppData\Roaming\Sublime Text 3\Packages\User
and then I founded this syntax file in my View
-> Syntax
-> User
-> zul
(the name of the file).
这篇关于sublimetext 3中具有.sublime-syntax文件类型的多种语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!