Community
    • Login

    Modifying existing language settings

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 4.3k 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.
    • Ilisuan Iannis PatriciuI
      Ilisuan Iannis Patriciu
      last edited by

      Hello!
      I would like to add some custom tags in Notepad++'s HTML syntax highlighting, so that both the tag and it’s attributes are colored accordingly.
      Is it possible to copy and modify OR import and edit the HTML language file from somewhere or do I have to do everything by hand (custom + official HTML tags) in the User-Defined Language window?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Ilisuan Iannis Patriciu
        last edited by

        @Ilisuan-Iannis-Patriciu ,

        The HTML syntax highlighter doesn’t have any user-defined keyword slots in the Style Configurator > HTML settings. Unfortunately, that means you can’t add them to the builtin lexer.

        So you could use UDL (though it won’t have all the features of the HTML lexer), or you can add extra highlighting to a builtin lexer using regexes via the script EnhanceAnyLexer.py that @Ekopalypse shares in his github repo

        PeterJonesP 1 Reply Last reply Reply Quote 1
        • Ilisuan Iannis PatriciuI
          Ilisuan Iannis Patriciu
          last edited by

          That’s a bummer. Oh well, thank you for your answer!

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Ilisuan Iannis Patriciu
            last edited by

            @Ilisuan-Iannis-Patriciu ,

            Actually, I just thought of and confirmed an alternative.

            The langs.xml config file (so probably in %AppData%\Notepad++\langs.xml if you have a normal installation) does list the standard tags that the HTML parser recognizes. If you follow best practices for editing config files, you can add a tag to the list, save, and then re-start Notepad++. For example, here’s a screenshot after I told Notepad++ that <aardvark> was a valid HTML tag, but not <anteater>:

            301c41c6-a472-426d-8cc1-3bb2c6736513-image.png

            Note that <aardvark> and its attributes are colored just like normal tags, but <anteater> is still in default color because it’s not a recognized tag name.

            1 Reply Last reply Reply Quote 5
            • Ilisuan Iannis PatriciuI
              Ilisuan Iannis Patriciu
              last edited by

              @PeterJones This worked just the way I wanted. Thanks!

              1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @PeterJones
                last edited by

                For future readers:

                Note from the future: In 2024, the HTML TAG style does have a box for user-defined keyword slots. I don’t remember when it was added, but it’s been there for a while now (I can guarantee at least since v8.6.6, but I think a lot longer than that). So if you want this, start by upgrading to the most recent Notepad++.

                Further, as I say here, I recently learned that the HTML lexer has the ability to enable “substyles” for the HTML TAG style, which you can assign your own color and your own list of keywords – so you could style your custom tags differently than the builtin tags if you want. Unfortunately, Notepad++ doesn’t (yet) enable those substyles, so you cannot do it natively in Notepad++. In this post, I share a script for the PythonScript which enables substyles – that specific post gives the example for PHP, but if you want to do the same for HTML, you would follow the same instruction, except edit the lists in class HTML_SubstyleLexer and append your colors/list definitions to the SCE_H_TAG in that class’s colorize.

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