management/front/dkha-web-sz-main/node_modules/highlight.js/lib/languages/json.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
/*
Language: JSON
Description: JSON (JavaScript Object Notation) is a lightweight data-interchange format.
Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
Website: http://www.json.org
Category: common, protocols
*/
function json(hljs) {
const LITERALS = {
literal: 'true false null'
};
const ALLOWED_COMMENTS = [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
];
const TYPES = [
2023-12-18 13:12:25 +08:00
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE
];
2024-01-16 21:26:16 +08:00
const VALUE_CONTAINER = {
end: ',',
endsWithParent: true,
excludeEnd: true,
2023-12-18 13:12:25 +08:00
contains: TYPES,
keywords: LITERALS
};
2024-01-16 21:26:16 +08:00
const OBJECT = {
begin: /\{/,
end: /\}/,
2023-12-18 13:12:25 +08:00
contains: [
{
className: 'attr',
2024-01-16 21:26:16 +08:00
begin: /"/,
end: /"/,
2023-12-18 13:12:25 +08:00
contains: [hljs.BACKSLASH_ESCAPE],
2024-01-16 21:26:16 +08:00
illegal: '\\n'
2023-12-18 13:12:25 +08:00
},
2024-01-16 21:26:16 +08:00
hljs.inherit(VALUE_CONTAINER, {
begin: /:/
})
].concat(ALLOWED_COMMENTS),
2023-12-18 13:12:25 +08:00
illegal: '\\S'
};
2024-01-16 21:26:16 +08:00
const ARRAY = {
begin: '\\[',
end: '\\]',
2023-12-18 13:12:25 +08:00
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'
};
2024-01-16 21:26:16 +08:00
TYPES.push(OBJECT, ARRAY);
ALLOWED_COMMENTS.forEach(function(rule) {
TYPES.push(rule);
});
2023-12-18 13:12:25 +08:00
return {
2024-01-16 21:26:16 +08:00
name: 'JSON',
2023-12-18 13:12:25 +08:00
contains: TYPES,
keywords: LITERALS,
illegal: '\\S'
};
2024-01-16 21:26:16 +08:00
}
module.exports = json;