l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

json.js (1356B)


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