Skip to content

Commit

Permalink
Slightly improve js template string regex
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Nov 16, 2023
1 parent 5fa8c2c commit 3887da8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
22 changes: 19 additions & 3 deletions package/patches/prismjs@1.29.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4041,7 +4041,7 @@ index 187d2cd74a6848a0ac8bd67da899ce72514dbdf9..c7868c8f10c2d18242b8721e786a1cd2

}(Prism));
diff --git a/components/prism-javascript.js b/components/prism-javascript.js
index 7eda6c617f96726ca2ea12cda1e39527d67e7295..c70b329ce36842500f9227f7e340bc86e97f4ba5 100644
index 7eda6c617f96726ca2ea12cda1e39527d67e7295..f81496b40e16e9afcee418ae1740d1a21598ed41 100644
--- a/components/prism-javascript.js
+++ b/components/prism-javascript.js
@@ -1,76 +1,50 @@
Expand Down Expand Up @@ -4154,7 +4154,7 @@ index 7eda6c617f96726ca2ea12cda1e39527d67e7295..c70b329ce36842500f9227f7e340bc86
},
'regex-delimiter': /^\/|\/$/,
'regex-flags': /^[a-z]+$/,
@@ -90,31 +64,19 @@ Prism.languages.insertBefore('javascript', 'keyword', {
@@ -90,38 +64,26 @@ Prism.languages.insertBefore('javascript', 'keyword', {
alias: 'function'
},
'parameter': [
Expand Down Expand Up @@ -4196,7 +4196,23 @@ index 7eda6c617f96726ca2ea12cda1e39527d67e7295..c70b329ce36842500f9227f7e340bc86
'hashbang': {
pattern: /^#!.*/,
greedy: true,
@@ -136,7 +98,7 @@ Prism.languages.insertBefore('javascript', 'string', {
alias: 'comment'
},
'template-string': {
- pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
+ pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})*\}|(?!\$\{)[^\\`])*`/g,
greedy: true,
inside: {
'template-punctuation': {
@@ -129,14 +91,14 @@ Prism.languages.insertBefore('javascript', 'string', {
alias: 'string'
},
'interpolation': {
- pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})*\}/,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation'
},
Expand Down
6 changes: 3 additions & 3 deletions package/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions website/src/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ Object.assign(js, {
alias: "comment",
},
"template-string": {
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})*\}|(?!\$\{)[^\\`])*`/g,
greedy: true,
inside: {
"template-punctuation": {
pattern: /^`|`$/,
alias: "string",
},
interpolation: {
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})*\}/,
lookbehind: true,
inside: {
"interpolation-punctuation": {
Expand Down

0 comments on commit 3887da8

Please sign in to comment.