Extending language definitions (for code highlighting) in notepad++

后端 未结 3 779
甜味超标
甜味超标 2020-12-05 10:18

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

相关标签:
3条回答
  • 2020-12-05 10:49

    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

    0 讨论(0)
  • 2020-12-05 10:51

    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:

    • How to write a scintilla 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:

    • Eclipse
    • Netbeans
    • GEdit (which has a Windows binary, if needed)
    • JetBrains PhpStorm

    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:

    • User Defined Languages
    • How to create a user-defined language in Notepad++ based on an existing language?

    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)

    • http://osdir.com/ml/editors.notepad++/2007-02/msg00021.html

    Hope that helps or gets you at least more of a head start!

    0 讨论(0)
  • 2020-12-05 10:53

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

    0 讨论(0)
提交回复
热议问题