Skip to content

Commit

Permalink
Adds support for comments in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusschulz committed Oct 25, 2018
1 parent bfbe446 commit b4f456f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion components/prism-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Prism.languages.json = {
'property': /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'property': {
pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
greedy: true
},
'string': {
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
greedy: true
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.

27 changes: 27 additions & 0 deletions tests/languages/json/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Line comment
"//": "//",

/* Block comment */
"/*": "*/"
}

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

[
["punctuation", "{"],
["comment", "// Line comment"],
["property", "\"//\""],
["operator", ":"],
["string", "\"//\""],
["punctuation", ","],
["comment", "/* Block comment */"],
["property", "\"/*\""],
["operator", ":"],
["string", "\"*/\""],
["punctuation", "}"]
]

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

Checks for single-line and multi-line comments.

0 comments on commit b4f456f

Please sign in to comment.