Skip to content

Commit

Permalink
Fix JSONP support (#1745)
Browse files Browse the repository at this point in the history
This PR fixes that JSON did not support [JSONP](https://en.wikipedia.org/wiki/JSONP) callback functions.

I also added a JSON example page.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Feb 26, 2019
1 parent 5bd182c commit b5041cf
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,13 @@
},
"json": {
"title": "JSON",
"alias": "jsonp",
"aliasTitles": {
"jsonp": "JSONP"
},
"owner": "CupOfTea696"
},
"jsonp": {
"title": "JSONP",
"require": "json",
"owner": "RunDevelopment"
},
"julia": {
"title": "Julia",
"owner": "cdagnino"
Expand Down
2 changes: 0 additions & 2 deletions components/prism-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ Prism.languages.json = {
alias: 'keyword'
}
};

Prism.languages.jsonp = Prism.languages.json;
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.

7 changes: 7 additions & 0 deletions components/prism-jsonp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Prism.languages.jsonp = Prism.languages.extend('json', {
'punctuation': /[{}[\]();,.]/
});

Prism.languages.insertBefore('jsonp', 'punctuation', {
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/
});
1 change: 1 addition & 0 deletions components/prism-jsonp.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>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vala":"clike","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","jsonp":"json","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vala":"clike","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;

var lang_data = {};

Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/languages/json/punctuation_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
----------------------------------------------------

[
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "["], ["punctuation", "]"],
["punctuation", "]"], ["punctuation", ","],
["punctuation", "}"], ["punctuation", ","],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "{"], ["punctuation", "}"],
["punctuation", "["], ["punctuation", "]"],
["punctuation", "]"], ["punctuation", ","],
["punctuation", "}"], ["punctuation", ","],
["punctuation", ","]
]
----------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions tests/languages/jsonp/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.
24 changes: 24 additions & 0 deletions tests/languages/jsonp/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{}
{ }
[]
],
},
,
;
()

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

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

Checks for punctuation.

0 comments on commit b5041cf

Please sign in to comment.