Adding a Tag Pair to an Existing Language

2012-09-29
2012-11-14
  • Please excuse this question because I have seen it asked several ways in many locations, but the answers as to how to accomplish it are still unclear to me.

    I am working on a project where I need to use additional tag pairs (begin and end tags) to my HTML file. For example I need to add recognition of _%! and !%_ and syntax highlight them in an HTML file. Ideally Id like the tags highlighted and the text between them highlighted as well (similar to inline ASP <%).

    Can I do this by changing the default language definition for HTML or do I actually have to compile a new lexer?

    Thanks in advance.

    Matt

     
  • Does anyone have any insight into how this can be done??

     
  • cchris
    cchris
    2012-10-13

    There are two ways you can do this with a builtin language. This is a worst case scenario because the lexers for HTML or XML don't think they need custom tags, so they don't provide support for them.
    First solution is to edit the C++ code of LexHTML.cxx to add the support. Then recompile SciLexer.dll. You'll need to do it again when Scintilla changes its dll and Notepad++ integrates such changes. It doesn't happen often.
    Second is to write your own lexer plugin. Reusing code from abovementioned file is recommended of course. While this is more work, you gain total control, donn't need to do it again later and can share the plugin. And if you prefer writing this woth a language other than C++, that's fine as long as you can produce a conformant dll with it.

    CChri

     
  • Chris,

    Thanks for the clarity of your response. I was thinking "this is harder than it should be…". Considering how flexible NPP is in every other respect.

    I work mainly in C# and not C++. I am thinking I could take your second approach and create a new library with my new tags…I'll have a look.

    Thanks!

    M