Skip to content

Commit 1c5f28a

Browse files
Chris-JohnstonmAAdhaTTah
authored andcommitted
Allow YAML strings to have trailing comments (#1602)
Updates the string regex to allow for strings that may have a trailing '#'. This uses a different pattern from other regex patterns, because only the string regex pattern is greedy, while the others are not. Fix #1601.
1 parent da474c7 commit 1c5f28a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

components/prism-yaml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Prism.languages.yaml = {
3131
alias: 'important'
3232
},
3333
'string': {
34-
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}))/m,
34+
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|\s*#))/m,
3535
lookbehind: true,
3636
greedy: true
3737
},

components/prism-yaml.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/yaml/string_feature.test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ foo: ""
33
bar: "fo\"obar"
44
foo: ''
55
bar: 'fo\'obar'
6+
foo: "foo" # bar
7+
bar: 'bar' # foo
68

79
----------------------------------------------------
810

@@ -15,7 +17,11 @@ bar: 'fo\'obar'
1517
["key", "foo"], ["punctuation", ":"],
1618
["string", "''"],
1719
["key", "bar"], ["punctuation", ":"],
18-
["string", "'fo\\'obar'"]
20+
["string", "'fo\\'obar'"],
21+
["key", "foo"], ["punctuation", ":"],
22+
["string", "\"foo\""], ["comment", "# bar"],
23+
["key", "bar"], ["punctuation", ":"],
24+
["string", "'bar'"], ["comment", "# foo"]
1925
]
2026

2127
----------------------------------------------------

0 commit comments

Comments
 (0)