l0bsterssg

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

xml.js (3538B)


      1 /*
      2 Language: HTML, XML
      3 Website: https://www.w3.org/XML/
      4 Category: common
      5 */
      6 
      7 function xml(hljs) {
      8   var XML_IDENT_RE = '[A-Za-z0-9\\._:-]+';
      9   var XML_ENTITIES = {
     10     className: 'symbol',
     11     begin: '&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;'
     12   };
     13   var XML_META_KEYWORDS = {
     14 	  begin: '\\s',
     15 	  contains:[
     16 	    {
     17 	      className: 'meta-keyword',
     18 	      begin: '#?[a-z_][a-z1-9_-]+',
     19 	      illegal: '\\n',
     20       }
     21 	  ]
     22   };
     23   var XML_META_PAR_KEYWORDS = hljs.inherit(XML_META_KEYWORDS, {begin: '\\(', end: '\\)'});
     24   var APOS_META_STRING_MODE = hljs.inherit(hljs.APOS_STRING_MODE, {className: 'meta-string'});
     25   var QUOTE_META_STRING_MODE = hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'meta-string'});
     26   var TAG_INTERNALS = {
     27     endsWithParent: true,
     28     illegal: /</,
     29     relevance: 0,
     30     contains: [
     31       {
     32         className: 'attr',
     33         begin: XML_IDENT_RE,
     34         relevance: 0
     35       },
     36       {
     37         begin: /=\s*/,
     38         relevance: 0,
     39         contains: [
     40           {
     41             className: 'string',
     42             endsParent: true,
     43             variants: [
     44               {begin: /"/, end: /"/, contains: [XML_ENTITIES]},
     45               {begin: /'/, end: /'/, contains: [XML_ENTITIES]},
     46               {begin: /[^\s"'=<>`]+/}
     47             ]
     48           }
     49         ]
     50       }
     51     ]
     52   };
     53   return {
     54     name: 'HTML, XML',
     55     aliases: ['html', 'xhtml', 'rss', 'atom', 'xjb', 'xsd', 'xsl', 'plist', 'wsf', 'svg'],
     56     case_insensitive: true,
     57     contains: [
     58       {
     59         className: 'meta',
     60         begin: '<![a-z]', end: '>',
     61         relevance: 10,
     62         contains: [
     63 				  XML_META_KEYWORDS,
     64 				  QUOTE_META_STRING_MODE,
     65 				  APOS_META_STRING_MODE,
     66 					XML_META_PAR_KEYWORDS,
     67 					{
     68 					  begin: '\\[', end: '\\]',
     69 					  contains:[
     70 						  {
     71 					      className: 'meta',
     72 					      begin: '<![a-z]', end: '>',
     73 					      contains: [
     74 					        XML_META_KEYWORDS,
     75 					        XML_META_PAR_KEYWORDS,
     76 					        QUOTE_META_STRING_MODE,
     77 					        APOS_META_STRING_MODE
     78 						    ]
     79 			        }
     80 					  ]
     81 				  }
     82 				]
     83       },
     84       hljs.COMMENT(
     85         '<!--',
     86         '-->',
     87         {
     88           relevance: 10
     89         }
     90       ),
     91       {
     92         begin: '<\\!\\[CDATA\\[', end: '\\]\\]>',
     93         relevance: 10
     94       },
     95       XML_ENTITIES,
     96       {
     97         className: 'meta',
     98         begin: /<\?xml/, end: /\?>/, relevance: 10
     99       },
    100       {
    101         className: 'tag',
    102         /*
    103         The lookahead pattern (?=...) ensures that 'begin' only matches
    104         '<style' as a single word, followed by a whitespace or an
    105         ending braket. The '$' is needed for the lexeme to be recognized
    106         by hljs.subMode() that tests lexemes outside the stream.
    107         */
    108         begin: '<style(?=\\s|>)', end: '>',
    109         keywords: {name: 'style'},
    110         contains: [TAG_INTERNALS],
    111         starts: {
    112           end: '</style>', returnEnd: true,
    113           subLanguage: ['css', 'xml']
    114         }
    115       },
    116       {
    117         className: 'tag',
    118         // See the comment in the <style tag about the lookahead pattern
    119         begin: '<script(?=\\s|>)', end: '>',
    120         keywords: {name: 'script'},
    121         contains: [TAG_INTERNALS],
    122         starts: {
    123           end: '\<\/script\>', returnEnd: true,
    124           subLanguage: ['javascript', 'handlebars', 'xml']
    125         }
    126       },
    127       {
    128         className: 'tag',
    129         begin: '</?', end: '/?>',
    130         contains: [
    131           {
    132             className: 'name', begin: /[^\/><\s]+/, relevance: 0
    133           },
    134           TAG_INTERNALS
    135         ]
    136       }
    137     ]
    138   };
    139 }
    140 
    141 module.exports = xml;