在记事本++中扩展语言定义(用于代码突出显示) [英] Extending language definitions (for code highlighting) in notepad++

查看:69
本文介绍了在记事本++中扩展语言定义(用于代码突出显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在 TWIG 中进行开发.它是一种非常简单且强大的 html 模板语言.

I've been doing development in TWIG lately. It is an html templating language that is very simple and robust.

我已将 notepad++ 设置为自动将 .twig 文件视为 html.没关系,但是我的树枝函数没有任何语法高亮显示.

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.

twig 语法非常简单(按设计)并且很容易添加到记事本++.问题是,我在这个主题上发现的一切要么是关于创建新的语言定义(我不想重新发明 html 定义),要么是修改语言中现有语法位的颜色.

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.

有没有办法复制语言定义,然后在记事本++中修改它?如果没有,notepad++ 有没有办法在现有的语言定义中添加额外的语法位?

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?

编辑

TWIG 是一种 html 模板语言/引擎.它们的语法与 html 相同,但为控制语句添加了一些打开/关闭标记(特别是 {% %}、{{ }} 和 {# #}).您可以在 twig 网站

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

编辑 #2

根据 Brian Deragon 的回答,我一直在调查 3 个文件.以下是我到目前为止所想出/所做的:

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 - 似乎定义了关键字,用于自动完成.我复制了一个名为 twig.xml 的文件
  • langs.model.xml - 同样是一个关键字列表,在 1 个 XML 文件中包含所有语言.我复制了 HTML 对象并用 twig 替换了 name 和 ext 参数.
  • stylers.model.xml - 有一个不同项目的列表,以及每个项目的样式信息(颜色、背景颜色、字体等).我复制了 HTML 部分并将 name 和 desc 参数更改为 twig.

这些更改完成后,我在 notepad++ 中打开了一个 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).

不过,stylers.model.xml 很有趣.每个条目都有一堆项目,定义如下:

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>

那些似乎是为不同元素定义样式的地方.我找不到定义这些元素的任何地方.langs.model.xml 有注释开始/结束的定义,但没有用于任何其他分隔符.我真正需要的是一个地方告诉记事本++将 { } 视为分隔符,就像它对 < 所做的一样.> 现在.

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.

编辑 #3

我也在查看 Notepad++ 的用户定义语言列表 http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files用户定义的语言使用不同的引擎,但我可能会在其中找到一个与 html 足够相似的引擎,我可以对其进行调整.

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.

推荐答案

我在这里为它制作了一个荧光笔:https://github.com/Banane9/notepadplusplus-twig

I made a Highlighter for it here: https://github.com/Banane9/notepadplusplus-twig

这篇关于在记事本++中扩展语言定义(用于代码突出显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆