Community
    • Login

    How to add keywords for the HTML syntax highlighter?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 361 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.
    • Mikael ElmbladM
      Mikael Elmblad
      last edited by

      What is the proper way to add keywords for the HTML syntax highlighter?

      The ‘Style Configurator’ for .HTML files does not have the ‘User-defined keywords’ field so that’s not the way. Or have I done something wrong perhaps, because I can’t even see the ‘Default keywords’ field for .HTML files.

      Debug info

      Notepad++ v8.5.8   (32-bit)
      Build time : Oct 15 2023 - 21:12:23
      Path : C:\Program Files (x86)\Notepad++\notepad++.exe
      Command Line : 
      Admin mode : OFF
      Local Conf mode : OFF
      Cloud Config : C:\Users\USERNAME\OneDrive\Backups\Notepad++\DEVICENAME
      OS Name : Windows 10 Home (64-bit)
      OS Version : 22H2
      OS Build : 19045.3570
      Current ANSI codepage : 1252
      Plugins : 
          ComparePlugin (2.0.2)
          ComparePlus (1.1)
          HTMLTag_unicode (1.4.1)
          MarkdownViewerPlusPlus (0.8.2)
          mimeTools (2.9)
          NppConverter (4.5)
          NppExport (0.4)
          NPPJSONViewer (2.0.6)
          NppMarkdownPanel (0.7.3)
          NppQCP (2)
          NppSnippets (1.7.1)
          NppUISpy (1.2)
          NppXmlTreeviewPlugin (2)
          PreviewHTML (1.3.2)
          QuickOpenPlugin (1.1)
          Remove Duplicate Lines (1.3)
          XMLTools (3.1.1.13)
      
      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Mikael Elmblad
        last edited by

        @Mikael-Elmblad said in How to add keywords for the HTML syntax highlighter?:

        WHAT IS THE PROPER WAY TO ADD KEYWORDS FOR THE HTML SYNTAX HIGHLIGHTER?

        Notepad++ uses IP from the Scintilla / Lexilla projects for syntax highlighting. The Lexilla lexer for HTML does not have a provision for user keywords. So there is no configuration that you can do, nor can the Notepad++ developer add that ability without effectively giving up on using the IP that it has used for more than a decade, and that isn’t likely to happen. If you wanted to put in an issue with the Lexilla project, you might convince them to add user keywords (or if your keywords are truly HTML keywords, they might add them directly).

        You could use the EnhanceAnyLexer plugin to add a regular expression to change the foreground of your extra keywords.

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

          @PeterJones said in How to add keywords for the HTML syntax highlighter?:

          The Lexilla lexer for HTML does not have a provision for user keywords.

          This was wrong, assuming “add keywords” meant adding new tags. You could obviously add new tags using the Style Configurator’s HTML > Tag > user-defined keywords. I think a year ago I was under the misunderstanding that you couldn’t add your own tags, because every time I had tried, I had done a mixedCase tag so I could easily identify it; I later learned that the lexer requires the keyword list to be all lowercase (which I thought was an odd limitation, because HTML itself is case-insensitive for tag names – but it has to do with the way that the lexer lowercases the tag text before comparing it to the list). So sorry for the misinformation last year.

          Further, as I recently learned, 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 2
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors