l0bsterssg

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

properties.js (1968B)


      1 /*
      2 Language: .properties
      3 Contributors: Valentin Aitken <valentin@nalisbg.com>, Egor Rogov <e.rogov@postgrespro.ru>
      4 Website: https://en.wikipedia.org/wiki/.properties
      5 Category: common, config
      6 */
      7 
      8 function properties(hljs) {
      9 
     10   // whitespaces: space, tab, formfeed
     11   var WS0 = '[ \\t\\f]*';
     12   var WS1 = '[ \\t\\f]+';
     13   // delimiter
     14   var DELIM = '(' + WS0+'[:=]'+WS0+ '|' + WS1 + ')';
     15   var KEY_ALPHANUM = '([^\\\\\\W:= \\t\\f\\n]|\\\\.)+';
     16   var KEY_OTHER = '([^\\\\:= \\t\\f\\n]|\\\\.)+';
     17 
     18   var DELIM_AND_VALUE = {
     19           // skip DELIM
     20           end: DELIM,
     21           relevance: 0,
     22           starts: {
     23             // value: everything until end of line (again, taking into account backslashes)
     24             className: 'string',
     25             end: /$/,
     26             relevance: 0,
     27             contains: [
     28               { begin: '\\\\\\n' }
     29             ]
     30           }
     31         };
     32 
     33   return {
     34     name: '.properties',
     35     case_insensitive: true,
     36     illegal: /\S/,
     37     contains: [
     38       hljs.COMMENT('^\\s*[!#]', '$'),
     39       // key: everything until whitespace or = or : (taking into account backslashes)
     40       // case of a "normal" key
     41       {
     42         begin: KEY_ALPHANUM + DELIM,
     43         returnBegin: true,
     44         contains: [
     45           {
     46             className: 'attr',
     47             begin: KEY_ALPHANUM,
     48             endsParent: true,
     49             relevance: 0
     50           }
     51         ],
     52         starts: DELIM_AND_VALUE
     53       },
     54       // case of key containing non-alphanumeric chars => relevance = 0
     55       {
     56         begin: KEY_OTHER + DELIM,
     57         returnBegin: true,
     58         relevance: 0,
     59         contains: [
     60           {
     61             className: 'meta',
     62             begin: KEY_OTHER,
     63             endsParent: true,
     64             relevance: 0
     65           }
     66         ],
     67         starts: DELIM_AND_VALUE
     68       },
     69       // case of an empty key
     70       {
     71         className: 'attr',
     72         relevance: 0,
     73         begin: KEY_OTHER + WS0 + '$'
     74       }
     75     ]
     76   };
     77 }
     78 
     79 module.exports = properties;