Skip to content

Commit cbe05ec

Browse files
JSON: Kinda fixed comment issue (#1853)
This is a partial workaround for the greedy matching bug so that pure JSON will always be matched correctly while JSON + comments might suffer from some issues.
1 parent 77e403c commit cbe05ec

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

components/prism-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Prism.languages.json = {
2-
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
32
'property': {
43
pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
54
greedy: true
@@ -8,6 +7,7 @@ Prism.languages.json = {
87
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
98
greedy: true
109
},
10+
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
1111
'number': /-?\d+\.?\d*(e[+-]?\d+)?/i,
1212
'punctuation': /[{}[\],]/,
1313
'operator': /:/,

components/prism-json.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.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"A": "/*",
3+
"B": "B",
4+
"C": "C"
5+
}
6+
7+
----------------------------------------------------
8+
9+
[
10+
["punctuation", "{"],
11+
["property", "\"A\""],
12+
["operator", ":"],
13+
["string", "\"/*\""],
14+
["punctuation", ","],
15+
["property", "\"B\""],
16+
["operator", ":"],
17+
["string", "\"B\""],
18+
["punctuation", ","],
19+
["property", "\"C\""],
20+
["operator", ":"],
21+
["string", "\"C\""],
22+
["punctuation", "}"]
23+
]
24+
25+
----------------------------------------------------
26+
27+
Checks for issue #1852.

0 commit comments

Comments
 (0)