8000 Powershell: Add lookbehind to fix function interpolation inside strin… · js-programming/prism@d2c026e · GitHub
[go: up one dir, main page]

Skip to content

Commit d2c026e

Browse files
committed
Powershell: Add lookbehind to fix function interpolation inside strings. Fix PrismJS#1361
1 parent a5331a6 commit d2c026e

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

components/prism-powershell.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Prism.languages.powershell = {
1515
greedy: true,
1616
inside: {
1717
'function': {
18-
pattern: /[^`]\$\(.*?\)/,
18+
pattern: /(^|[^`])\$\(.*?\)/,
19+
lookbehind: true,
1920
// Populated at end of file
2021
inside: {}
2122
}

components/prism-powershell.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/powershell/string_feature.test

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,54 @@ an empty '' string
99
'can''t'
1010
"a simple #comment string"
1111
"has $interpolated <# variables #>"
12+
"$($expression)"
13+
"`$(escaped expression)"
1214

1315
----------------------------------------------------
1416

1517
[
1618
["string", ["\"a simple string\""]],
1719
["string", [
18-
"\"has ",["variable", "$interpolated"]," variables\""]
19-
],
20+
"\"has ", ["variable", "$interpolated"], " variables\""
21+
]],
2022
["string", [
21-
"\"has",
23+
"\"has ",
2224
[
2325
"function",
2426
[
25-
" $",
27+
"$",
2628
["punctuation", "("],
2729
["variable", "$nesting"],
2830
["operator", "-and"],
2931
["string", "'interpolation'"],
3032
["punctuation", ")"]
3133
]
3234
],
33-
"\""]
34-
],
35+
"\""
36+
]],
3537
["string", ["\"string `\"with`\" escaping\""]],
3638
["string", "'non-interpolated $string'"],
3739
["string", "'also ''with'' escaping'"],
3840
["string", "'''twas also escaped'"],
39-
"\r\nan empty ",["string", "''"], " string\r\n",
41+
"\r\nan empty ", ["string", "''"], " string\r\n",
4042
["string", "'can''t'"],
4143
["string", ["\"a simple #comment string\""]],
4244
["string", [
43-
"\"has ",["variable", "$interpolated"]," <# variables #>\""]
44-
]
45+
"\"has ", ["variable", "$interpolated"], " <# variables #>\""
46+
]],
47+
["string", [
48+
"\"",
49+
["function", [
50+
"$",
51+
["punctuation", "("],
52+
["variable", "$expression"],
53+
["punctuation", ")"]
54+
]],
55+
"\""
56+
]],
57+
["string", [
58+
"\"`$(escaped expression)\""
59+
]]
4560
]
4661

4762
----------------------------------------------------

0 commit comments

Comments
 (0)
0