1 | /*
|
2 | Language: JSON
|
3 | Description: JSON (JavaScript Object Notation) is a lightweight data-interchange format.
|
4 | Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
|
5 | Website: http://www.json.org
|
6 | Category: common, protocols, web
|
7 | */
|
8 |
|
9 | function json(hljs) {
|
10 | const ATTRIBUTE = {
|
11 | className: 'attr',
|
12 | begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
|
13 | relevance: 1.01
|
14 | };
|
15 | const PUNCTUATION = {
|
16 | match: /[{}[\],:]/,
|
17 | className: "punctuation",
|
18 | relevance: 0
|
19 | };
|
20 | // normally we would rely on `keywords` for this but using a mode here allows us
|
21 | // to use the very tight `illegal: \S` rule later to flag any other character
|
22 | // as illegal indicating that despite looking like JSON we do not truly have
|
23 | // JSON and thus improve false-positively greatly since JSON will try and claim
|
24 | // all sorts of JSON looking stuff
|
25 | const LITERALS = {
|
26 | beginKeywords: [
|
27 | "true",
|
28 | "false",
|
29 | "null"
|
30 | ].join(" ")
|
31 | };
|
32 |
|
33 | return {
|
34 | name: 'JSON',
|
35 | contains: [
|
36 | ATTRIBUTE,
|
37 | PUNCTUATION,
|
38 | hljs.QUOTE_STRING_MODE,
|
39 | LITERALS,
|
40 | hljs.C_NUMBER_MODE,
|
41 | hljs.C_LINE_COMMENT_MODE,
|
42 | hljs.C_BLOCK_COMMENT_MODE
|
43 | ],
|
44 | illegal: '\\S'
|
45 | };
|
46 | }
|
47 |
|
48 | export { json as default };
|