From 7334750fd54a85dc6cc99b94374d4f7b2e0bf3ef Mon Sep 17 00:00:00 2001 From: Alexander Jank Date: Fri, 22 Sep 2023 12:23:22 +0200 Subject: [PATCH 1/3] fix(twig): encapsulate twig highlighter in a function --- components/prism-twig.js | 90 ++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/components/prism-twig.js b/components/prism-twig.js index 59442d449e..a3e3b8c0d9 100644 --- a/components/prism-twig.js +++ b/components/prism-twig.js @@ -1,44 +1,46 @@ -Prism.languages.twig = { - 'comment': /^\{#[\s\S]*?#\}$/, - - 'tag-name': { - pattern: /(^\{%-?\s*)\w+/, - lookbehind: true, - alias: 'keyword' - }, - 'delimiter': { - pattern: /^\{[{%]-?|-?[%}]\}$/, - alias: 'punctuation' - }, - - 'string': { - pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, - inside: { - 'punctuation': /^['"]|['"]$/ - } - }, - 'keyword': /\b(?:even|if|odd)\b/, - 'boolean': /\b(?:false|null|true)\b/, - 'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/, - 'operator': [ - { - pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/, - lookbehind: true - }, - /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/ - ], - 'punctuation': /[()\[\]{}:.,]/ -}; - -Prism.hooks.add('before-tokenize', function (env) { - if (env.language !== 'twig') { - return; - } - - var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g; - Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern); -}); - -Prism.hooks.add('after-tokenize', function (env) { - Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig'); -}); +(function (Prism) { + Prism.languages.twig = { + 'comment': /^\{#[\s\S]*?#\}$/, + + 'tag-name': { + pattern: /(^\{%-?\s*)\w+/, + lookbehind: true, + alias: 'keyword' + }, + 'delimiter': { + pattern: /^\{[{%]-?|-?[%}]\}$/, + alias: 'punctuation' + }, + + 'string': { + pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, + inside: { + 'punctuation': /^['"]|['"]$/ + } + }, + 'keyword': /\b(?:even|if|odd)\b/, + 'boolean': /\b(?:false|null|true)\b/, + 'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/, + 'operator': [ + { + pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/, + lookbehind: true + }, + /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/ + ], + 'punctuation': /[()\[\]{}:.,]/ + }; + + Prism.hooks.add('before-tokenize', function (env) { + if (env.language !== 'twig') { + return; + } + + var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g; + Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern); + }); + + Prism.hooks.add('after-tokenize', function (env) { + Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig'); + }); +}(Prism)); From 0344271d554c2726e7516e811f61ae0a8546fbb4 Mon Sep 17 00:00:00 2001 From: Alexander Jank Date: Fri, 22 Sep 2023 14:55:59 +0200 Subject: [PATCH 2/3] chore(lint): reindent lines --- components/prism-twig.js | 88 ++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/components/prism-twig.js b/components/prism-twig.js index a3e3b8c0d9..e03f6cd181 100644 --- a/components/prism-twig.js +++ b/components/prism-twig.js @@ -1,46 +1,46 @@ (function (Prism) { - Prism.languages.twig = { - 'comment': /^\{#[\s\S]*?#\}$/, - - 'tag-name': { - pattern: /(^\{%-?\s*)\w+/, - lookbehind: true, - alias: 'keyword' - }, - 'delimiter': { - pattern: /^\{[{%]-?|-?[%}]\}$/, - alias: 'punctuation' - }, - - 'string': { - pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, - inside: { - 'punctuation': /^['"]|['"]$/ - } - }, - 'keyword': /\b(?:even|if|odd)\b/, - 'boolean': /\b(?:false|null|true)\b/, - 'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/, - 'operator': [ - { - pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/, - lookbehind: true - }, - /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/ - ], - 'punctuation': /[()\[\]{}:.,]/ - }; - - Prism.hooks.add('before-tokenize', function (env) { - if (env.language !== 'twig') { - return; - } - - var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g; - Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern); - }); - - Prism.hooks.add('after-tokenize', function (env) { - Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig'); - }); + Prism.languages.twig = { + 'comment': /^\{#[\s\S]*?#\}$/, + + 'tag-name': { + pattern: /(^\{%-?\s*)\w+/, + lookbehind: true, + alias: 'keyword' + }, + 'delimiter': { + pattern: /^\{[{%]-?|-?[%}]\}$/, + alias: 'punctuation' + }, + + 'string': { + pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, + inside: { + 'punctuation': /^['"]|['"]$/ + } + }, + 'keyword': /\b(?:even|if|odd)\b/, + 'boolean': /\b(?:false|null|true)\b/, + 'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/, + 'operator': [ + { + pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/, + lookbehind: true + }, + /[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/ + ], + 'punctuation': /[()\[\]{}:.,]/ + }; + + Prism.hooks.add('before-tokenize', function (env) { + if (env.language !== 'twig') { + return; + } + + var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g; + Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern); + }); + + Prism.hooks.add('after-tokenize', function (env) { + Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig'); + }); }(Prism)); From b6a0166443dd0b893a72961d975c2550959ccd99 Mon Sep 17 00:00:00 2001 From: Alexander Jank Date: Fri, 22 Sep 2023 19:07:35 +0200 Subject: [PATCH 3/3] style: remove trailing spaces / tabs --- components/prism-twig.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/prism-twig.js b/components/prism-twig.js index e03f6cd181..0dcdf4fba8 100644 --- a/components/prism-twig.js +++ b/components/prism-twig.js @@ -1,7 +1,7 @@ (function (Prism) { Prism.languages.twig = { 'comment': /^\{#[\s\S]*?#\}$/, - + 'tag-name': { pattern: /(^\{%-?\s*)\w+/, lookbehind: true, @@ -11,7 +11,7 @@ pattern: /^\{[{%]-?|-?[%}]\}$/, alias: 'punctuation' }, - + 'string': { pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, inside: { @@ -30,16 +30,16 @@ ], 'punctuation': /[()\[\]{}:.,]/ }; - + Prism.hooks.add('before-tokenize', function (env) { if (env.language !== 'twig') { return; } - + var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g; Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern); }); - + Prism.hooks.add('after-tokenize', function (env) { Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig'); });