• Login
Community
  • Login

Extend syntax highlighting for a certain language

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 5 Posters 4.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W
    whitecat
    last edited by Nov 5, 2020, 1:51 PM

    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

    A P 2 Replies Last reply Nov 5, 2020, 2:00 PM Reply Quote 0
    • A
      Alan Kilborn @whitecat
      last edited by Nov 5, 2020, 2:00 PM

      @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…

      1 Reply Last reply Reply Quote 1
      • P
        PeterJones @whitecat
        last edited by Nov 5, 2020, 2:18 PM

        @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:

        1. 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
        2. 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!

        M 1 Reply Last reply Nov 5, 2020, 2:24 PM Reply Quote 1
        • M
          Michael Vincent @PeterJones
          last edited by Nov 5, 2020, 2:24 PM

          @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:

          b5038dac-4d7b-4bb0-9e67-1a59a2950a89-image.png

          Cheers.

          P 1 Reply Last reply Nov 5, 2020, 2:37 PM Reply Quote 0
          • P
            PeterJones @Michael Vincent
            last edited by Nov 5, 2020, 2:37 PM

            @Michael-Vincent ,

            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.

            de3d64df-ce4a-424e-8ac6-ef66339ad420-image.png

            M 1 Reply Last reply Nov 5, 2020, 2:47 PM Reply Quote 0
            • M
              Michael Vincent @PeterJones
              last edited by Nov 5, 2020, 2:47 PM

              @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):

              254c0763-a5f5-46b3-a520-21089942df02-image.png

              W 1 Reply Last reply Nov 5, 2020, 3:34 PM Reply Quote 0
              • N
                Nick Brown
                last edited by Nick Brown Nov 5, 2020, 3:33 PM Nov 5, 2020, 3:32 PM

                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>
                
                1 Reply Last reply Reply Quote 2
                • W
                  whitecat @Michael Vincent
                  last edited by whitecat Nov 5, 2020, 3:34 PM Nov 5, 2020, 3:34 PM

                  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 and stylers.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

                  P 1 Reply Last reply Nov 5, 2020, 4:44 PM Reply Quote 2
                  • P
                    PeterJones @whitecat
                    last edited by Nov 5, 2020, 4:44 PM

                    @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

                    W 1 Reply Last reply Nov 5, 2020, 5:41 PM Reply Quote 3
                    • W
                      whitecat @PeterJones
                      last edited by Nov 5, 2020, 5:41 PM

                      @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 shares

                      Interesting, 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

                      1 Reply Last reply Reply Quote 2
                      2 out of 10
                      • First post
                        2/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors