Skip to content

Commit

Permalink
JSON: Greedy comments (#2479)
Browse files Browse the repository at this point in the history
Comments are now greedy allowing them to break strings, properties, and each other.
  • Loading branch information
RunDevelopment committed Jul 30, 2020
1 parent f0f8210 commit 158caf5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion components/prism-json.js
Expand Up @@ -8,7 +8,10 @@ Prism.languages.json = {
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
greedy: true
},
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
'punctuation': /[{}[\],]/,
'operator': /:/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-json.min.js

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

4 changes: 2 additions & 2 deletions tests/languages/json/comment_feature.test
@@ -1,5 +1,5 @@
{
// Line comment
// Line comment ""
"//": "//",

/* Block comment */
Expand All @@ -10,7 +10,7 @@

[
["punctuation", "{"],
["comment", "// Line comment"],
["comment", "// Line comment \"\""],
["property", "\"//\""],
["operator", ":"],
["string", "\"//\""],
Expand Down

0 comments on commit 158caf5

Please sign in to comment.