SVG syntax highlighting



  • I code HTML SVG and Javascript html pages.
    I have noticed that if I selefct HTML language, I get only HTML and Java syntax highlighting, without SVG tags.
    If I select XML language, I get SVG syntax highlighting but I loose the HTML and JavaScript syntax highlighting. How can I get XML and HTML language selected? can I have a different syntax highlighting language? based on my need?



  • The current lexers (the portion of the program which determines what highlighting should be applied to each piece of text) are single-language lexers, so the HTML lexer doesn’t really know CSS or JavaScript even when they are embedded in your HTML, the XML lexer doesn’t know the uniqueness of HTML, or the uniqueness of SVG.

    The lexers that ship with Notepad++ were determined by an old version of the Scintilla editor component that’s embedded in Notepad++; any feature requests for those default lexers would have to go through Scintilla’s feature-request (after first verifying that Scintilla didn’t already make those updates). Then, after it’s implemented, you would have to ask the Notepad++ developer to upgrade the Scintilla in Notepad++: since the last time Notepad++ updated it’s Scintilla was from 3.34 to 3.56 in June 2015, and Scintilla is currently on 4.1.3, the chances of a Scintilla-upgrade in Notepad++ are unfortunately slim at this point.

    Alternatively, there is a User Defined Language (UDL) lexer, which would allow you to define some of your own syntax, but it is somewhat limited, and you might not get all the features you want from trying to make a catch-all lexer there.
    It is possible to code a Notepad++ plugin that implements a lexer – though that’s a lot of effort. One-time forum-regular @Claudia-Frank started on a PythonScript-based lexer which is similar to UDL, but allows regular-expressions to define the syntax; you might be able to make that work for your needs; my collection of links to her effort is at https://notepad-plus-plus.org/community/topic/16164/bug-javascript-multiline-character-not-understood-by-notepad/11



  • Thanks a lot Peter.
    If I simply need to add some tags to the current HTML language?

    can I edit langs.xml in notepad++ folder,
    and add tags to <Keywords…> part of the file?

    <Language name=“html” ext=“html htm shtml shtm xhtml xht hta” commentLine="" commentStart="<!–" commentEnd="–>">
    <Keywords name=“instre1”>!doctype a abbr accept accept-char



  • For the file to edit: If you have an installed copy (%ProgramFiles%\Notepad++ or %ProgramFiles(x86)%\Notepad++), then look first in %AppData%\Notepad++\langs.xml: if there is a langs.xml there, then edit that one. If you’ve got a portable version of Notepad++, or there isn’t a langs.xml there, then you would edit the one in the same directory as notepad++.exe.

    However, my quick experiment with a portable copy showed that it doesn’t recognize my new keyword when I do that for HTML. Some of the languages, like SQL’s KEYWORD style or Perl’s INSTRUCTION WORD style have “User-defined keywords”, which will get stored in stylers.xml (in %AppData%\Notepad++ for installed, or your exe-directory for portable), but the HTML lexer apparently doesn’t have any user-defined keywords.



  • Update: I was wrong. When I added “PeterAddedThis PeterAddedThat” to the end of the Keywords list in langs.xml, it didn’t recognize it. But when I added “peter peteraddedthis peteraddedthat” in the alphabetically-correct location without capitalization, saved, then reloaded Notepad++, I could add

    <peter added this></peter>
    <peterx></peterx>
    <peteraddedthis></peteraddedthis>
    <PeterAddedThat>hehe <peter></peter></PeterAddedThat>
    

    and all but the <peterx></peterx> would be highlighted as if they were real tags.

    I then added “peteraddedlast PeterAddedX” to the end of the list (ie, not in alphabetical order). That made it recognize <peteraddedlast></peteraddedlast> and <PeterAddedLast></PeterAddedLast>, but <peteraddedx></peteraddedx> and <PeterAddedX></PeterAddedX> are not recognized.

    So if you edit the right langs.xml, and then add the keywords in lower case to the appropriate list, there is a good chance that you will see the added tags highlighted as valid HTML tags.

    Good luck.



  • cool thanks for the effort