我最近一直在 TWIG 中进行开发。它是一种非常简单且强大的 html 模板语言。
我已将 notepad++ 设置为自动将 .twig 文件视为 html。没关系,但我的树枝函数上没有任何语法突出显示。
twig 语法非常简单(按照设计),并且很容易添加到 notepad++ 中。问题是,我在这个主题上找到的所有内容要么是关于创建新的语言定义(并且我不想重新发明 html 定义),要么是修改语言中现有语法位的颜色。
有没有办法复制语言定义然后在notepad++中修改它?如果没有,记事本++中是否有任何方法可以向现有语言定义添加额外的语法位?
编辑
TWIG 是一种 html 模板语言/引擎。它们的语法与 html 相同,只是添加了一些用于控制语句的打开/关闭标记(特别是 {% %}、{{ }} 和 {# #})。您可以在 twig 网站 阅读更多相关信息
编辑 #2
根据答案来自 Brian Deragon,我一直在调查 3 个文件。这是我到目前为止所想出/完成的:
- \plugins\APIs\html.xml - 似乎定义了关键字,用于自动完成。我复制了一份名为 twig.xml langs.model.xml 的文件
- - 同样是一个关键字列表,所有语言都位于 1 个 XML 文件中。我复制了 HTML 对象并用 twig 替换了 name 和 ext 参数。
- stylers.model.xml - 具有不同项目的列表以及每个项目的样式信息(颜色、背景颜色、字体等)。我复制了 HTML 部分并将名称和 desc 参数更改为 twig。
完成这些更改后,我在记事本++中打开了一个twig文件,希望看到它在语言选项中列出。遗憾的是,它还没有出现,让我相信其中一些是硬编码的(因此我想要的可能是不可能的)。
不过,stylers.model.xml 很有趣。每个条目都有一堆项目,定义如下:
<LexerType name="twig" desc="TWIG" ext="">
<WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="COMMENT" styleID="9" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TAG" styleID="1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TAGEND" styleID="11" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
...
</LexerType>
这些似乎是为不同元素定义样式的地方。但我找不到定义这些元素的任何地方。 langs.model.xml 有注释开始/结束的定义,但没有任何其他分隔符的定义。我真正需要的是一个地方告诉 notepad++ 将 { } 视为分隔符,就像它对 < 所做的那样。 >现在。
编辑 #3
我也在查看 notepad++ 的用户定义语言列表 http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files
用户定义的语言使用不同的引擎,但我也许能够在那里找到一个与 html 足够相似的引擎,以便我可以适应它。
I've been doing development in TWIG lately. It is an html templating language that is very simple and robust.
I've set notepad++ to automatically treat .twig files as html. This is ok, but I don't get any syntax highlighting on my twig functions.
The twig syntax is incredibly simple (by design) and would be easy to add to notepad++. The problem is, everything I find on this subject is either about creating a new language definition (and I do not want to reinvent the html definition), or modifying the color for existing syntax bits in a language.
Is there any way to copy a language definition and then modify it in notepad++? If not, is there any way in notepad++ to add extra syntax bits to an existing language definition?
edit
TWIG is an html template language/engine. they syntax for it is the same as html, with the addition of a few open/close tags (specifically {% %}, {{ }}, and {# #}) for control statements. you can read more about it at the twig website
edit #2
Based on the answer from Brian Deragon, I have been investigating 3 files. Heres what I've figured out/done so far:
- \plugins\APIs\html.xml - Seems to define keywords, for autocomplete. I made a copy of the file named twig.xml
- langs.model.xml - Again, a list of keywords, with all the languages in 1 XML file. I copied the HTML object and replaced the name and ext parameters with twig.
- stylers.model.xml - Has a list of different items, and style information (color, bg color, font, etc) for each. I copied the HTML section and changed the name and desc parameters to twig.
Those changes done, I opened up a twig file in notepad++, hoping to see it listed in the language options. Sadly, it has not appeared, leading me to believe that some of this is hard coded (and thus what I want might not be possible).
The stylers.model.xml is interesting, though. Each entry has a bunch of items, defined like this:
<LexerType name="twig" desc="TWIG" ext="">
<WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="COMMENT" styleID="9" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TAG" styleID="1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TAGEND" styleID="11" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
...
</LexerType>
Those seem to be where the styles are defined for the different elements. I can't find anywhere where those elements are defined though. langs.model.xml has a definition for comment start/end, but not for any other delimiters. what I really need is a place to tell notepad++ to treat { } as a delimiter, much like it does for < > now.
edit #3
I am also looking at this list of user defined languages for notepad++ http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files
User defined languages use a different engine, but i might be able to find one in there that is similar to html enough that I can adapt it.
发布评论
评论(3)
您应该能够复制并编辑 XML 定义文件 (html.xml);只要您不需要超出基础知识的东西,例如代码折叠、基于案例处理块或多个条件的高级着色、前导字符的单独格式、标签着色、基于 xml 的注释、语言混合(嵌入式脚本),支持鸭子类型着色等。如果您需要任何“高级”功能,您需要编写自己的词法分析器,在这种情况下,下面的大部分内容都适用。
即便如此,我下面列出的模板应该可以让您在自己的语言定义文件上抢占先机。
据我所知,Notepad++ 使用 Scintilla Lexers 来确定其代码规则。
您必须创建自己的词法分析器,但是...HTML Scintilla Lexer 已包含在 Scintilla 源代码。
然后,您可以使用 插件 插入自定义词法分析器,例如 Gary 的 Lua 荧光笔插件。
用于构建自定义词法分析器的资源:
话虽如此,Geany 与 Notepad++ 非常相似(基于相同的引擎 Scintilla),因此您可能想看看它是否已经到过为 Geany 完成的,或者是否有一个开源项目正在开发中。这至少会给你一个良好的开端。
如果这没有帮助,还有内置 Twig 支持的 IDE 和编辑器,例如:
GEdit 已发布该语言的 XML 定义 此处,这可能有助于在创建您的自己的定义文件或词法分析器;还有 Twig 的人发布的另一个模板 这里这可能会有一些帮助。
以下是我能找到的用于创建自定义词法分析器/用户定义语言的最佳 Notepad++ 特定教程:
如果您想勇敢地构建自己的 Scintilla dll,请参考这些线程,看看有人让它工作,并显示在语言列表中(使用上一个/下一个线程查看回复的消息,或线程索引;它是一个邮件列表,因此它的 UI 不是最好的)
希望对您有所帮助或至少让您获得更多领先一步!
You should be able to just copy and edit the XML definition file (html.xml); as long as you don't need stuff beyond the basics, like code-folding, advanced coloring based off of case-handling blocks or multiple conditionals, separate formatting for lead characters, label coloring, xml-based commenting, language mixing (coloring of embedded scripts), support for coloring of duck-types, etc. If you need anything "advanced" you need to write your own lexer, in which case most of the below applies.
Even still, the templates I listed below should give you a head-start on your own language definition file.
As far as I'm aware, Notepad++ uses Scintilla Lexers for determining its code rules.
You'll have to create your own lexer, but...the HTML Scintilla Lexer is already included in the Scintilla source code.
Then you would insert your custom lexer using a plug-in, like Gary's Lua Highlighter Plugin.
Resources for building a custom lexer:
That being said, Geany is very similar to Notepad++ (based off the same engine, Scintilla), so you might want to see whether it's already been done for Geany, or whether there's an open-source project for it in the works. This would at least give you a head start.
If that doesn't help, there are IDEs and editors with Twig support built-in, like:
GEdit has published their XML definition of the language here, which might help as a reference when creating your own definition file or lexer; there's also another template published by the guys from Twig here that might be of some help.
Here are the best Notepad++-specific tutorials for creating custom lexer's/User Defined Languages I can find:
If you want to get brave and build your own Scintilla dll, reference these threads, to see a guy who got it working, and to show up in the language list (use the previous/next thread message to see responses, or the thread index; it's a mailing list, so its UI isn't the best)
Hope that helps or gets you at least more of a head start!
我在这里为它做了一个荧光笔:
https://github.com/Banane9/notepadplusplus-twig
I made a Highlighter for it here:
https://github.com/Banane9/notepadplusplus-twig
这篇文章可能重复:https://superuser。 com/questions/40876/assigning-custom-extensions-to-a-languages-syntax-highlighting-in-notepad
您所需要做的就是在中添加自定义扩展设置 -> 样式配置器
单击 HTML 并在用户分机框中添加您的分机。
编辑:如果您想向您的语言添加更多规则,您可能需要在 notepad++->plugins->API 中添加另一个 XML
如果您认为它像 HTML,只需复制 html.xml 并另存为 twig.xml
向此 XML 文件添加更多规则
Possible duplicate of this post: https://superuser.com/questions/40876/assigning-custom-extensions-to-a-languages-syntax-highlighting-in-notepad
All you need to do is add your custom extension in Settings->Style Configurator
Click on HTML and add your extension in the User Ext box.
EDIT: If you want to add more rules to your language, you might have to add another XML in notepad++->plugins->APIs
If you think it's like HTML, just copy over html.xml and save as twig.xml
Add more rules to this XML file