8000 Adds support for comments in JSON (#1595) · PrismJS/prism@8720b3e · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 8720b3e

Browse files
mariusschulzmAAdhaTTah
authored andcommitted
Adds support for comments in JSON (#1595)
While JSON doesn't explicitly support comments, they're commonly used and there are supersets of JSON that do make comments available. PrismJS is not a linter, and this is a useful feature to include when displaying JSON.
1 parent 6d1a2c6 commit 8720b3e

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

components/prism-json.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Prism.languages.json = {
2-
'property': /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
2+
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
3+
'property': {
4+
pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
5+
greedy: true
6+
},
37
'string': {
48
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
59
greedy: true

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.
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
// Line comment
3+
"//": "//",
4+
5+
/* Block comment */
6+
"/*": "*/"
7+
}
8+
9+
----------------------------------------------------
10+
11+
[
12+
["punctuation", "{"],
13+
["comment", "// Line comment"],
14+
["property", "\"//\""],
15+
["operator", ":"],
16+
["string", "\"//\""],
17+
["punctuation", ","],
18+
["comment", "/* Block comment */"],
19+
["property", "\"/*\""],
20+
["operator", ":"],
21+
["string", "\"*/\""],
22+
["punctuation", "}"]
23+
]
24+
25+
----------------------------------------------------
26+
27+
Checks for single-line and multi-line comments.

0 commit comments

Comments
 (0)
0