Skip to content

Commit 158caf5

Browse files
JSON: Greedy comments (#2479)
Comments are now greedy allowing them to break strings, properties, and each other.
1 parent f0f8210 commit 158caf5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

components/prism-json.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Prism.languages.json = {
88
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
99
greedy: true
1010
},
11-
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
11+
'comment': {
12+
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
13+
greedy: true
14+
},
1215
'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
1316
'punctuation': /[{}[\],]/,
1417
'operator': /:/,

components/prism-json.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/json/comment_feature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
// Line comment
2+
// Line comment ""
33
"//": "//",
44

55
/* Block comment */
@@ -10,7 +10,7 @@
1010

1111
[
1212
["punctuation", "{"],
13-
["comment", "// Line comment"],
13+
["comment", "// Line comment \"\""],
1414
["property", "\"//\""],
1515
["operator", ":"],
1616
["string", "\"//\""],

0 commit comments

Comments
 (0)