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