From a98b5ea6fe8e8cc98a55e0fd793e6e8660ea31c1 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 30 Dec 2021 19:47:21 +0100 Subject: chore: add prismjs for syntax highlighting --- public/prism/prism-batch.js | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 public/prism/prism-batch.js (limited to 'public/prism/prism-batch.js') diff --git a/public/prism/prism-batch.js b/public/prism/prism-batch.js new file mode 100644 index 0000000..02b9634 --- /dev/null +++ b/public/prism/prism-batch.js @@ -0,0 +1,100 @@ +(function (Prism) { + var variable = /%%?[~:\w]+%?|!\S+!/; + var parameter = { + pattern: /\/[a-z?]+(?=[ :]|$):?|-[a-z]\b|--[a-z-]+\b/im, + alias: 'attr-name', + inside: { + punctuation: /:/, + }, + }; + var string = /"(?:[\\"]"|[^"])*"(?!")/; + var number = /(?:\b|-)\d+\b/; + + Prism.languages.batch = { + comment: [ + /^::.*/m, + { + pattern: /((?:^|[&(])[ \t]*)rem\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, + lookbehind: true, + }, + ], + label: { + pattern: /^:.*/m, + alias: 'property', + }, + command: [ + { + // FOR command + pattern: + /((?:^|[&(])[ \t]*)for(?: \/[a-z?](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* \S+ in \([^)]+\) do/im, + lookbehind: true, + inside: { + keyword: /\b(?:do|in)\b|^for\b/i, + string: string, + parameter: parameter, + variable: variable, + number: number, + punctuation: /[()',]/, + }, + }, + { + // IF command + pattern: + /((?:^|[&(])[ \t]*)if(?: \/[a-z?](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* (?:not )?(?:cmdextversion \d+|defined \w+|errorlevel \d+|exist \S+|(?:"[^"]*"|(?!")(?:(?!==)\S)+)?(?:==| (?:equ|geq|gtr|leq|lss|neq) )(?:"[^"]*"|[^\s"]\S*))/im, + lookbehind: true, + inside: { + keyword: /\b(?:cmdextversion|defined|errorlevel|exist|not)\b|^if\b/i, + string: string, + parameter: parameter, + variable: variable, + number: number, + operator: /\^|==|\b(?:equ|geq|gtr|leq|lss|neq)\b/i, + }, + }, + { + // ELSE command + pattern: /((?:^|[&()])[ \t]*)else\b/im, + lookbehind: true, + inside: { + keyword: /^else\b/i, + }, + }, + { + // SET command + pattern: + /((?:^|[&(])[ \t]*)set(?: \/[a-z](?:[ :](?:"[^"]*"|[^\s"/]\S*))?)* (?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im, + lookbehind: true, + inside: { + keyword: /^set\b/i, + string: string, + parameter: parameter, + variable: [variable, /\w+(?=(?:[*\/%+\-&^|]|<<|>>)?=)/], + number: number, + operator: /[*\/%+\-&^|]=?|<<=?|>>=?|[!~_=]/, + punctuation: /[()',]/, + }, + }, + { + // Other commands + pattern: + /((?:^|[&(])[ \t]*@?)\w+\b(?:"(?:[\\"]"|[^"])*"(?!")|[^"^&)\r\n]|\^(?:\r\n|[\s\S]))*/m, + lookbehind: true, + inside: { + keyword: /^\w+\b/, + string: string, + parameter: parameter, + label: { + pattern: /(^\s*):\S+/m, + lookbehind: true, + alias: 'property', + }, + variable: variable, + number: number, + operator: /\^/, + }, + }, + ], + operator: /[&@]/, + punctuation: /[()']/, + }; +})(Prism); -- cgit v1.2.3