Skip to content

Commit

Permalink
feat(highlight): add JSON support (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Cáceres committed Dec 23, 2016
1 parent 3abd7c7 commit 2ecc669
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions js/deps/highlight.js
Expand Up @@ -1127,6 +1127,43 @@ hljs.registerLanguage('javascript', function(hljs) {
};
});

hljs.registerLanguage('json', function(hljs) {
var LITERALS = {literal: 'true false null'};
var TYPES = [
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE
];
var VALUE_CONTAINER = {
end: ',', endsWithParent: true, excludeEnd: true,
contains: TYPES,
keywords: LITERALS
};
var OBJECT = {
begin: '{', end: '}',
contains: [
{
className: 'attr',
begin: /"/, end: /"/,
contains: [hljs.BACKSLASH_ESCAPE],
illegal: '\\n',
},
hljs.inherit(VALUE_CONTAINER, {begin: /:/})
],
illegal: '\\S'
};
var ARRAY = {
begin: '\\[', end: '\\]',
contains: [hljs.inherit(VALUE_CONTAINER)], // inherit is a workaround for a bug that makes shared modes with endsWithParent compile only the ending of one of the parents
illegal: '\\S'
};
TYPES.splice(TYPES.length, 0, OBJECT, ARRAY);
return {
contains: TYPES,
keywords: LITERALS,
illegal: '\\S'
};
});

hljs.registerLanguage('xml', function(hljs) {
var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
var TAG_INTERNALS = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -48,7 +48,7 @@
},
"scripts": {
"build": "npm run copydeps && npm run hb:build && npm run build:highlight && npm run build:respec-w3c-common",
"build:highlight": "cd node_modules/highlight.js/ && npm install && node ./tools/build.js -n xml javascript css http markdown xquery && cd ../../",
"build:highlight": "cd node_modules/highlight.js/ && npm install && node ./tools/build.js -n xml javascript css http markdown xquery json && cd ../../",
"build:respec-w3c-common": "./tools/build-w3c-common.js",
"jscs": "jscs --esnext tests tools js/core/markdown.js js/core/utils.js js/w3c/linter.js",
"jscs:fix": "jscs --esnext --fix tests",
Expand Down

0 comments on commit 2ecc669

Please sign in to comment.