1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
| /*
| 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 = [
| hljs.QUOTE_STRING_MODE,
| hljs.C_NUMBER_MODE
| ];
| const VALUE_CONTAINER = {
| end: ',',
| endsWithParent: true,
| excludeEnd: true,
| contains: TYPES,
| keywords: LITERALS
| };
| const OBJECT = {
| begin: /\{/,
| end: /\}/,
| contains: [
| {
| className: 'attr',
| begin: /"/,
| end: /"/,
| contains: [hljs.BACKSLASH_ESCAPE],
| illegal: '\\n'
| },
| hljs.inherit(VALUE_CONTAINER, {
| begin: /:/
| })
| ].concat(ALLOWED_COMMENTS),
| illegal: '\\S'
| };
| const 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.push(OBJECT, ARRAY);
| ALLOWED_COMMENTS.forEach(function(rule) {
| TYPES.push(rule);
| });
| return {
| name: 'JSON',
| contains: TYPES,
| keywords: LITERALS,
| illegal: '\\S'
| };
| }
|
| module.exports = json;
|
|