Menu

Gherkin Syntax Highlighting in Notepad++

Notepad++ is an excellent text editor for Windows. It is free, lightweight, feature-rich, and extendable. It can handle just about any programming language out there. I use it all the time, especially for config files and quick edits that don’t require a bulky IDE. Seriously, if you don’t have it, download it now. (Not a Windows user? Check out Gherkin Syntax Highlighting in Atom.)

One of the nifty features in Notepad++ is User Defined Language, which allows users to customize the syntax highlighting for any language. This is invaluable if you use an obscure language or even create your own. To access this feature in version 7.2.2, simply navigate to the Language menu option and choose Define your language…. From there, you can create new user language and set stylers for keywords, operators, and other language facets. Stylers can set font color, size, and style. Users can also import and export UDLs as XML files for sharing. Since the highlighting doesn’t rely upon a context-free grammar, it has its limits. For example, keywords may still be highlighted when not actually being used as keywords in the language. Nevertheless, it’s better than nothing.

You *could* play around with the Notepad++ UDL to make it highlight numbers, but I question if you *should*. In Gherkin, numbers are treated just like any other plain text for a step. There is nothing special about them. If you want numbers to be used as step arguments, then I recommend the best practice of surrounding arguments with double-quotes. For example: Given I have a basket with “3” cucumbers. The UDL I provided will highlight any arguments surrounded by double-quotes.

I have able to Import it into V 7.6.6 I had to save the raw XML as suggested above. It tells me that the import is successful but then I can’t figure out how to use the language. It is not highlighted as the example above.

Andy thanks for your help. I was finally able to get it work, clearly I was doing something wrong. The only question that I have is when you write out the example tables, what do I need to do in order to have it format correctly?