Extend syntax highlighting for a certain language
-
Hi there,
for a documentation system I extended HTML with some new tags in order to style them via CSS. This works very well in the user’s browser, but of course Notepad++ doesn’t highlight “my” newly invented tags when editing the documentation files. So I tried to hack Notepad++ and finally found the correct location to achieve my goal: I edited the file
%APPDATA%\Notepad++\langs.xml
(section<Language name="html">
) and inserted “my” tags into the space-separated list. Restarted Notepad++ - it works.Now I am wondering whether there is a more “official” way to do the same: Yes, I have read https://npp-user-manual.org/docs/user-defined-language-system/, but this only describes how to create a new language definition from scratch, which would be overkill in my case as the standard HTML syntax highlighting works, just without “my” tags.
There is a similar post in this forum (https://community.notepad-plus-plus.org/topic/15568), but locked and without any answer, so I’m trying it here again…
Any hint would be appreciated.
whitecat
-
@whitecat said in Extend syntax highlighting for a certain language:
Now I am wondering whether there is a more “official” way to do the same
You mean to get your changes actually into the Notepad++ “sources” so that future releases have these additions?
If so, then yes, you file a “feature request” (see the FAQ section of this forum).
Of course, any such request will be reviewed for appropriateness.
Meaning that you should supply a reference for things you are adding, which shows that the “new tags” are official parts of the language (sorry not an HTML/CSS expert).
But the part where you say “my newly invented tags” worries me for this aspect…If you are looking for a “more official” way to do what you’ve already done…hmmm, don’t think there is one; could be wrong…
-
@whitecat said in Extend syntax highlighting for a certain language:
wondering whether there is a more “official” way to do the same
Not really. To add keywords to a builtin language, there are two local options:
- Settings>Style Configurator for that language: some languages have one or more of their styles with “User-defined keywords”. For example, Perl > INSTRUCTION WORD has that field. Others, like HTML, don’t have any styles that are default-extendible. Words you add in that method get stored in your
stylers.xml
config file - Editing
%APPDATA%\Notepad++\langs.xml
directly, as you did
And the official way to add it for everyone (ie, the “non-local” option) is as @Alan-Kilborn described.
The first two are “official”, in that if Notepad++ Developers didn’t want you to edit such configurations yourself, those config files would not have been made human-readable, or they wouldn’t have been made configurable at all. Those config files are there for you to make Notepad++ as useful to you as you can. Enjoy!
- Settings>Style Configurator for that language: some languages have one or more of their styles with “User-defined keywords”. For example, Perl > INSTRUCTION WORD has that field. Others, like HTML, don’t have any styles that are default-extendible. Words you add in that method get stored in your
-
@whitecat
@PeterJones said in Extend syntax highlighting for a certain language:Others, like HTML, don’t have any styles that are default-extendible
Interesting - I see HTML TAG and TAGEND styles as extendable with the default
stylers.xml
:Cheers.
-
I see HTML TAG and TAGEND styles as extendable with the default
stylers.xml
Weird. I just did a fresh unzip of either 7.9-x64 or 7.9.1-x64, and neither one showed the User-defined keywords (or even Default keywords) box for TAG.
-
@PeterJones said in Extend syntax highlighting for a certain language:
Weird.
Weird-er:
I don’t see TAG as extendable in my custom style even though
Default stylers.xml
shows it (as my above post screenshot): -
Try adding keywordClass=“instre1” attribute to the end of the WordStyle Tag for TAG in Stylers.xml as below:
<LexerType name="html" desc="HTML" ext="aspx ascx"> <WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT" styleID="9" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="NUMBER" styleID="5" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="DOUBLESTRING" styleID="6" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="SINGLESTRING" styleID="7" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="TAG" styleID="1" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="instre1"/> <WordsStyle name="TAGEND" styleID="11" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="TAGUNKNOWN" styleID="2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="ATTRIBUTE" styleID="3" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="ATTRIBUTEUNKNOWN" styleID="4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="SGMLDEFAULT" styleID="21" fgColor="000000" bgColor="A6CAF0" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="CDATA" styleID="17" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="VALUE" styleID="19" fgColor="FF8000" bgColor="FEFDE0" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="ENTITY" styleID="10" fgColor="000000" bgColor="FEFDE0" fontName="" fontStyle="2" fontSize="" /> </LexerType>
-
The same here - no input field for user-defined keywords (Notepad++ v7.9, 32 bit on Windows 8.1 Pro 64 bit). But my own customisations in
%APPDATA%\Notepad++\langs.xml
are nevertheless working! (It’s just for my own installation of Notepad++, not to be released in public, noone else than myself will ever use them.)Now I tried to show “my” tags in a different colour than the genuine HTML tags, fiddled around with
langs.xml
andstylers.xml
in my %APPDATA% and “instre2” and “type1” values in these XML files, but have failed so far. Maybe this isn’t possible at all as there is something hardcoded into Notepad++ which isn’t customisable by editing these XML files.whitecat
-
@whitecat said in Extend syntax highlighting for a certain language:
Now I tried to show “my” tags in a different colour than the genuine HTML tags
That’s a different problem than adding tags to the list of valid tags.
There isn’t support in the standard Style Configurator or config files for that. However, you can add extra highlighting to a builtin lexer (like the HTML lexer) using regexes via the script
EnhanceAnyLexer.py
that @Ekopalypse shares in his github repo -
@PeterJones said in Extend syntax highlighting for a certain language:
That’s a different problem than adding tags to the list of valid tags.
Of course it is - after my success with patching
langs.xml
in order to colour my invented tags, I wanted to go one step further. Now I know that it’s not possible.via the script
EnhanceAnyLexer.py
that @Ekopalypse sharesInteresting, but for my purposes too complicated. So I’m going to stick with my patched
langs.xml
, this solves the main problem, the rest would just be “nice to have”.Thank you for your support.
whitecat