Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/prism-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Prism.languages.json = {
greedy: true
},
'number': /-?\d+\.?\d*(e[+-]?\d+)?/i,
'punctuation': /[{}[\],]/,
// function is for JSONP
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/,
'punctuation': /[{}[\]();,]/,
'operator': /:/,
'boolean': /\b(?:true|false)\b/,
'null': {
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.

19 changes: 19 additions & 0 deletions examples/prism-json.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h2>Full example</h2>
<pre><code>{
"data": {
"labels": [
"foo",
"bar"
],
"series": [
[ 0, 1, 2, 3 ],
[ 0, -4, -8, -12 ]
]
},
// we even support comments
"error": null,
"status": "Ok"
}</code></pre>

<h2>JSONP</h2>
<pre><code>callback({ "data": null });</code></pre>
13 changes: 13 additions & 0 deletions tests/languages/json/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
callback();

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

[
["function", "callback"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"]
]
----------------------------------------------------

Checks for callback functions.
16 changes: 10 additions & 6 deletions tests/languages/json/punctuation_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
],
},
,
;
()

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

[
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "["], ["punctuation", "]"],
["punctuation", "]"], ["punctuation", ","],
["punctuation", "}"], ["punctuation", ","],
["punctuation", ","]
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "["], ["punctuation", "]"],
["punctuation", "]"], ["punctuation", ","],
["punctuation", "}"], ["punctuation", ","],
["punctuation", ","],
["punctuation", ";"],
["punctuation", "("], ["punctuation", ")"]
]
----------------------------------------------------

Expand Down