Skip to content

Commit

Permalink
Allow YAML strings to have trailing comments (#1602)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Chris-Johnston authored and mAAdhaTTah committed Oct 29, 2018
1 parent da474c7 commit 1c5f28a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Prism.languages.yaml = {
alias: 'important'
},
'string': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}))/m,
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|\s*#))/m,
lookbehind: true,
greedy: true
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-yaml.min.js

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

8 changes: 7 additions & 1 deletion tests/languages/yaml/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ foo: ""
bar: "fo\"obar"
foo: ''
bar: 'fo\'obar'
foo: "foo" # bar
bar: 'bar' # foo

----------------------------------------------------

Expand All @@ -15,7 +17,11 @@ bar: 'fo\'obar'
["key", "foo"], ["punctuation", ":"],
["string", "''"],
["key", "bar"], ["punctuation", ":"],
["string", "'fo\\'obar'"]
["string", "'fo\\'obar'"],
["key", "foo"], ["punctuation", ":"],
["string", "\"foo\""], ["comment", "# bar"],
["key", "bar"], ["punctuation", ":"],
["string", "'bar'"], ["comment", "# foo"]
]

----------------------------------------------------
Expand Down

0 comments on commit 1c5f28a

Please sign in to comment.