• Login
Community
  • Login

Custom XML syntax Highlighting? Custom XML UDL?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
14 Posts 4 Posters 2.0k 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.
  • L
    LogicSequence
    last edited by Apr 9, 2022, 11:10 PM

    I’m working with a video game that uses XML sheets as it’s primary scripting and definition source. Here’s what i’d like to be able to do: Basically add keyword highlighting to the XML syntax highlighting. I’d like a XML syntax (or UDL) that behaves exactly like the default built in XML syntax highlighting, but has the ability to override and highlight certain keywords in tags and/or tag attributes. This would make it easier for me to script events, etc. for the game as the tags are read as action commends, etc.

    So is there a way to Edit the Default XML highlighting to include keyword highlighting? Or is there a way to make a UDL that acts like the XML highlighting (highlighting tags, collapsing tags, etc.) but also gives me the other range of options a UDL does?

    Example (Default):
    alt text

    Example (Desired):
    alt text

    Thanks in advance for any help!

    A 1 Reply Last reply Apr 9, 2022, 11:12 PM Reply Quote 0
    • A
      Alan Kilborn @LogicSequence
      last edited by Apr 9, 2022, 11:12 PM

      @logicsequence said in Custom XML syntax Highlighting? Custom XML UDL?:

      is there a way to Edit the Default XML highlighting to include keyword highlighting?

      Nope.

      Suggest you look into “EnhanceAnyLexer” plugin. It lets a default lexer do its job and then adds to it. See HERE .

      L 3 Replies Last reply Apr 9, 2022, 11:29 PM Reply Quote 0
      • L
        LogicSequence @Alan Kilborn
        last edited by LogicSequence Apr 9, 2022, 11:31 PM Apr 9, 2022, 11:29 PM

        @alan-kilborn I can’t seem to get that to install, i followed the directions on the page but N++ doesn’t recognize it as an installed plugin.

        Nevermind stupid mistake on my part.

        1 Reply Last reply Reply Quote 0
        • L
          LogicSequence @Alan Kilborn
          last edited by Apr 9, 2022, 11:34 PM

          @alan-kilborn BUUUUT… how the hell do i use this? I don’t want to waste your time, but if you could give me like a 10 sec how-to that would be great. If you can’t, no problems, though.

          1 Reply Last reply Reply Quote 0
          • L
            LogicSequence @Alan Kilborn
            last edited by Apr 9, 2022, 11:42 PM

            @alan-kilborn I’ve got the plugin installed, but i don’t know what it’s asking me to do whatsoever.

            P 1 Reply Last reply Apr 10, 2022, 12:03 AM Reply Quote 0
            • P
              PeterJones @LogicSequence
              last edited by PeterJones Apr 10, 2022, 12:03 AM Apr 10, 2022, 12:03 AM

              @logicsequence ,

              I had only previously used Eko’s pythonscript-based version. But since you asked so nice (well, actually, because I was curious as to how the interface would be), I downloaded it, and within about 10 minutes was able to get it to:

              61a68293-b775-497a-9383-cdfba9f7951f-image.png

              At the end of your EnhanceAnyLexerConfig.ini, add:

              [xml]
              16711935 = \b(KeywordLists|WordsStyle)\b
              

              Amazingly, the plugin sees that the file has changed, and applies the changes instantly.

              In case you were curious as to my figuring-out procedure, I took the example python from that file:

              ;[python]
              ;1077960 = \b(cls|self)\b
              ;excluded_styles = 1,3,4,6,7,12,16,17,18,19
              

              Uncommented (removed the ;) and changed the header to [xml] instead of [python]. I then created some dummy tags in my example file that were <cls> and <self>, and saw they were a mustardy color. So that implies it was actually doing something. Then I added KeywordLists to the regex, so it said ` \b(cls|self|KeywordLists)\b, and now that tag is also mustard. Eureka!

              To change the color, I know that colors are usually 0xRRGGBB or 0xBBGGRR (and I knew that Notepad++ used the latter) – it would be nice if @Ekopalypse would add a note about the color values in the example ini. So I saw your color was 0xFF00FF. (which then doesn’t matter which is red and which is blue). I converted that to decimal, which is 16711935, and replaced that. It changed to purply text! WooHoo!

              I then added WordsStyle after a new | and got rid of the cls|self|, yielding the config file section I showed originally.

              The excluded styles will help you avoid coloring those same terms in unwanted lexer situations, but that’s not critical from the get-go.

              So, that’s working. Expanding to more keywords is up to you. For a beta plugin, that was easy enough.

              ( @Ekopalypse , my other suggestion would be to allow #BBGGRR as the color value as well. But great conversion from the original pythonscript, BTW.)

              L 2 Replies Last reply Apr 10, 2022, 12:14 AM Reply Quote 4
              • L
                LogicSequence @PeterJones
                last edited by Apr 10, 2022, 12:14 AM

                @peterjones You’re amazing and i love you, that’s exactly what i needed to know. The hex to decimal thing threw me off too, but i can just google a converter. Looks like this will do exactly what i want. I am in all your debts. Thank you @alan-kilborn for the recommendation as well!

                1 Reply Last reply Reply Quote 1
                • L
                  LogicSequence @PeterJones
                  last edited by LogicSequence Apr 10, 2022, 6:07 AM Apr 10, 2022, 6:06 AM

                  @peterjones Just noticed, btw, that when converting from HEX color values to decimal values you need to invert the red and blue value before putting into a converter to get the color to display properly (i think this is probably a bug?).

                  So if you want, say, darkish purple, it would be a HEX value of #80 00 ff, but if you convert that value to DEC it won’t show properly. You have to input #ff 00 80 to get it to work. Just FYI for anyone wondering why colors aren’t working as they might have expected.

                  A 1 Reply Last reply Apr 10, 2022, 11:01 AM Reply Quote 0
                  • A
                    Alan Kilborn @LogicSequence
                    last edited by Apr 10, 2022, 11:01 AM

                    @logicsequence said in Custom XML syntax Highlighting? Custom XML UDL?:

                    you need to invert the red and blue value before putting into a converter to get the color to display properly (i think this is probably a bug?

                    No bug, really. It originates with how Windows decided to handle colors, i.e., in the COLORREF definition, see HERE .

                    1 Reply Last reply Reply Quote 4
                    • E
                      Ekopalypse
                      last edited by Apr 11, 2022, 9:08 AM

                      Sorry I’m late to the party, and thank you for the interest in this plugin. Hex notation of a colour is also supported, I’ll make sure to update the sample configuration to make this clear.
                      As for the #bbccff notation, I think this should be easy to do, as for me this means I replace # with 0x and the code remains the same.

                      @LogicSequence - can I ask you how I can improve the documentation in the config file to make it easier to understand for starters?

                      1 Reply Last reply Reply Quote 2
                      • E
                        Ekopalypse
                        last edited by Apr 11, 2022, 3:22 PM

                        A new version v.0.2.0 was created which added the #color notation and made it “interactive”.
                        Unfortunately, the “#” is a comment character that makes the rest of the line look like it is inactive, which of course it is not.

                        319c0493-ff27-40a1-814a-f378d0bc532f-image.png

                        P 1 Reply Last reply Apr 11, 2022, 3:44 PM Reply Quote 4
                        • P
                          PeterJones @Ekopalypse
                          last edited by Apr 11, 2022, 3:44 PM

                          @ekopalypse

                          Thanks. I don’t know why I didn’t try 0x when # didn’t work.

                          But yes, having that in the documentation is a definite improvement.

                          The other thing I would suggest in the comments would be to phrase it:

                          ; A colour is a number in the range 0 - 16777215.
                          ; The notation is either pure digits or a hex notation starting with 0x or #, 
                          ; such as 0xff00ff or #ff00ff.
                          ; Please note: 
                          ; * red goes in the lowest byte (0x0000FF)
                          ; * green goes in the center byte (0x00FF00)
                          ; * blue goes in the biggest byte (0xFF0000) 
                          ; * this BGR order might conflict with your expectation of RGB order.
                          ; * see Microsoft COLORREF documentation https://docs.microsoft.com/en-us/windows/win32/gdi/colorref
                          
                          E 1 Reply Last reply Apr 11, 2022, 3:53 PM Reply Quote 4
                          • E
                            Ekopalypse @PeterJones
                            last edited by Apr 11, 2022, 3:53 PM

                            @peterjones
                            Thank you - the repo is already updated and the next version will include it.

                            P 1 Reply Last reply Apr 11, 2022, 3:54 PM Reply Quote 2
                            • P
                              PeterJones @Ekopalypse
                              last edited by Apr 11, 2022, 3:54 PM

                              To borrow an idiom from GitHub: 🚀

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