Skip to content

Instantly share code, notes, and snippets.

@rocketworm
Last active August 22, 2023 11:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rocketworm/e1bf9d55469f3c3bbae0bbcc0fa2956e to your computer and use it in GitHub Desktop.
Save rocketworm/e1bf9d55469f3c3bbae0bbcc0fa2956e to your computer and use it in GitHub Desktop.
SyntaxHighlighter Custom Brush: Gherkin
/**
* Author: Michael Hall
* URL: http://www.bankofcanada.ca/
* License: GPL-2 | GPL-3
*/
SyntaxHighlighter.brushes.Gherkin = function()
{
/**
* Filters out the delimiters and values out of tables.
* @param match: the contents of the matching text
* @param regexInfo: regular expression info
* @returns: list of SyntaxHighlighter.Match objects
*/
function processTable(match, regexInfo){
return [
new SyntaxHighlighter.Match('|',match.index,'keyword'),
new SyntaxHighlighter.Match(match[0].substr(1),match.index+1,'value')
];
}
var keywords = 'Given When And Then Feature Scenario Outline Template Background But Examples';
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' }, // comments using #
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // "string"
{ regex: /"""[^"]*"""/gm, css: 'string' }, // multiline string (""" ..... """)
{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi, css: 'value' }, // numbers
{ regex: new RegExp(this.getKeywords(keywords), 'gmi'), css: 'keyword' }, // keywords
{ regex: /@[^@\r\n\t ]+/gi, css: 'preprocessor' }, //annotations
{ regex: /\|.*?(?=\|)/g, func: processTable }, //Tables
{ regex: /\|/g, css: 'keyword' }, //Excess table delimiters
{ regex: /(&lt;|<).*?(&gt;|>)/gi, css: 'value' } //values from tables
];
};
SyntaxHighlighter.brushes.Gherkin.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Gherkin.aliases = ['gherkin', 'behat'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment