Web Sources Framework: Syntax Highlighting for Notepad++

Mp3tag Web Sources syntax highlighting for Notepad++

If you develop a Web Sources Script for Mp3tag you may find it useful to highlight your commands and syntax in specific colours. In addition Notepad++ allows code folding. For example, with if , else , and endif , it will define fold regions so that you can fold from if to else , from else to endif , and (assuming there is no else clause) from if to endif.

Notepad++ provides a so called User Defined Language system. The UDL interface allows the user to define rules for formatting normal text, keywords, comments, numbers, folding...

Requirements

Notepad++
Mp3tag Language Definition Export.xml v1.20
compressed in this downloadable file:
Mp3tag Language Definition Export v1.2.zip (1,2 KB)

This UDL defintion file contains all the known commands from the Mp3tag Web Sources Framework as of 12.01.2022.

Instructions

  1. Extract the XML from the above ZIP file.
  2. Import the Mp3tag Language Definition Export.xml

I suggest to use the Notepad++ menu Language -> User Defined Language -> Define Your Language and there the Import… button. Navigate to the source XML file Mp3tag Language Definition Export.xml, click Open and this UDL for Mp3tag will be available after a Notepad++ restart and reload of already opened content.

If you load a *.src or *.inc text file, the colours and folding will be applied automatically. You can change the UDL Language at any time using the Notepad++ Language menu.

How does it look?

Can I adjust the colours?

Sure. Use the Notepad++ menu Language -> User Defined Language -> Define Your Language and there choose the User language: Mp3tag src inc from the drop down box.
image

Click on the Tab where you want to change the colour for your commands
image

and then on the Styler button

You can choose whatever colour you like.

Version History

2022-02-22: v1.2 - One change, details see here
2022-02-07: v1.1 - Internal changes only
2022-01-12: v1.0 - First Public Release

Feedback

Please let me know if you find any error or inconsistency with this UDL definition.

3 Likes

2022-02-22 - Update v1.2

  • CHG: Position of "IfNot" in "Folders in code1, open" changed, to better detect the longer word "IfNotOutput" first (and completely).
1 Like

Thanks for this great idea. I have been working with this UDL definition for some time and have found a small inconsistency. Under Operators & Delimiter the Delimiter 1, that has Open: " and Close: " also needs under Escape: \ to be defined, because without that the syntax highlighting will stop at \" that is often used in regular expressions, e.g. in the WS script MusicBrainz.src.

Also a second delimiter with Open: [ and Close: ] could be defined and seems to me to be a replacement for the keywords in square brackets in the 2nd group of the keywors list. This list is not complete, it misses the (undocumented) [PreviewUrl] .

Thank you for your feedback @yorickausyps

[PreviewUrl] will be added to the second keyword list.

Then do you ask for changes like this?
(I'm not sure if I fully understand your request)

Could you please provide some test strings to see the difference?

For the first change I see the result:
BackSlash

But for the second one with the [ ] ?

please use the following excerpt from Discogs Release ID.src to try the second change with [...]

[Name]=Discogs.com
[BasedOn]=www.discogs.com
[PreviewUrl]=http://www.discogs.com/release/%s
[AlbumUrl]=https://api.discogs.com/releases/%s
[WordSeparator]=%20
[SearchBy]=Discogs ID||$if2(%DISCOGS_RELEASE_ID%,$if2(%DISCOGS_RELEASE_ID%,$if2(%DISCOGSID%,%DISCOGS-ID%)))||%s
[UserAgent]=1
[Encoding]=url-utf-8

[ParserScriptIndex]=...

Thank you very much for you quick reply!

Do you prefer to see all the defined keywords (and following text) from the "keywords group #2" in black color like this?
EckigeKlammern

You say that this does not affect other occurrences of [ ] as in regular expressions?

@yorickausyps
Could you please have a look at this side effect for values in apostrophes '[ and ]'
(it is only really visible if you set the foreground color of the "Delimiter 2 style" to Bold:)
Apostrophe

What do you think?

As I prefer to use the dark mode I had to set all background colors to black (or a dark color) and most foregrounds to a bright color.

The code example from MusicBrainz shows, that if the square brackets are used as delimiters in the UDL the Escape: \ must also be set, to find the corresponding brackets in the Searchby expression.
So far I did not find another example where the [ ] affect highlighting, because most regular expressions are surrounded by quotes:

sayregexp "(?<= id=\")[-0-9a-y]{34,40}(?=\")" ", " "<title>"

It seems to me that the outer quotes have precedence over the inner brackets and therefore the quotes define the highlighting. I think I should read the manual.