From 19abe58e910dc2d4a4f04fca463c257d0b4ef304 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 5 Apr 2024 13:51:34 +0200 Subject: [PATCH] add handling of string interpolation in Prism #321 --- lib/js/prism.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/js/prism.js b/lib/js/prism.js index 642a0a5ee..beb9177d3 100755 --- a/lib/js/prism.js +++ b/lib/js/prism.js @@ -24,6 +24,31 @@ Prism.languages.insertBefore('scheme', 'string', { greedy: true } }); +// modification of PrismJS JavaScript string interpolation +Prism.languages.insertBefore('scheme', 'string', { + 'template-string': { + pattern: /#"(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\"])*"/, + greedy: true, + inside: { + 'template-punctuation': { + pattern: /^#"|"$/, + alias: 'string' + }, + 'interpolation': { + pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, + lookbehind: true, + inside: { + 'interpolation-punctuation': { + pattern: /^\$\{|\}$/, + alias: 'punctuation' + }, + rest: Prism.languages.scheme + } + }, + 'string': /[\s\S]+/ + } + } +}); // properties of object literals Prism.languages.insertBefore('scheme', 'string', { variable: {