comparison third_party/highlight/es/languages/json.js @ 157:2db6253f355d

[ThirdParty] Added highlight library for better readability on blog.
author June Park <parkjune1995@gmail.com>
date Tue, 13 Jan 2026 19:18:47 -0800
parents
children
comparison
equal deleted inserted replaced
156:cd35e600ae34 157:2db6253f355d
1 /*! `json` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: JSON
7 Description: JSON (JavaScript Object Notation) is a lightweight data-interchange format.
8 Author: Ivan Sagalaev <[email protected]>
9 Website: http://www.json.org
10 Category: common, protocols, web
11 */
12
13 function json(hljs) {
14 const ATTRIBUTE = {
15 className: 'attr',
16 begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
17 relevance: 1.01
18 };
19 const PUNCTUATION = {
20 match: /[{}[\],:]/,
21 className: "punctuation",
22 relevance: 0
23 };
24 const LITERALS = [
25 "true",
26 "false",
27 "null"
28 ];
29 // NOTE: normally we would rely on `keywords` for this but using a mode here allows us
30 // - to use the very tight `illegal: \S` rule later to flag any other character
31 // - as illegal indicating that despite looking like JSON we do not truly have
32 // - JSON and thus improve false-positively greatly since JSON will try and claim
33 // - all sorts of JSON looking stuff
34 const LITERALS_MODE = {
35 scope: "literal",
36 beginKeywords: LITERALS.join(" "),
37 };
38
39 return {
40 name: 'JSON',
41 aliases: ['jsonc'],
42 keywords:{
43 literal: LITERALS,
44 },
45 contains: [
46 ATTRIBUTE,
47 PUNCTUATION,
48 hljs.QUOTE_STRING_MODE,
49 LITERALS_MODE,
50 hljs.C_NUMBER_MODE,
51 hljs.C_LINE_COMMENT_MODE,
52 hljs.C_BLOCK_COMMENT_MODE
53 ],
54 illegal: '\\S'
55 };
56 }
57
58 return json;
59
60 })();
61 ;
62 export default hljsGrammar;