l0bsterssg

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

latex.js (1517B)


      1 /*
      2 Language: LaTeX
      3 Author: Vladimir Moskva <vladmos@gmail.com>
      4 Website: https://www.latex-project.org
      5 Category: markup
      6 */
      7 
      8 function latex(hljs) {
      9   var COMMAND = {
     10     className: 'tag',
     11     begin: /\\/,
     12     relevance: 0,
     13     contains: [
     14       {
     15         className: 'name',
     16         variants: [
     17           {begin: /[a-zA-Z\u0430-\u044f\u0410-\u042f]+[*]?/},
     18           {begin: /[^a-zA-Z\u0430-\u044f\u0410-\u042f0-9]/}
     19         ],
     20         starts: {
     21           endsWithParent: true,
     22           relevance: 0,
     23           contains: [
     24             {
     25               className: 'string', // because it looks like attributes in HTML tags
     26               variants: [
     27                 {begin: /\[/, end: /\]/},
     28                 {begin: /\{/, end: /\}/}
     29               ]
     30             },
     31             {
     32               begin: /\s*=\s*/, endsWithParent: true,
     33               relevance: 0,
     34               contains: [
     35                 {
     36                   className: 'number',
     37                   begin: /-?\d*\.?\d+(pt|pc|mm|cm|in|dd|cc|ex|em)?/
     38                 }
     39               ]
     40             }
     41           ]
     42         }
     43       }
     44     ]
     45   };
     46 
     47   return {
     48     name: 'LaTeX',
     49     aliases: ['tex'],
     50     contains: [
     51       COMMAND,
     52       {
     53         className: 'formula',
     54         contains: [COMMAND],
     55         relevance: 0,
     56         variants: [
     57           {begin: /\$\$/, end: /\$\$/},
     58           {begin: /\$/, end: /\$/}
     59         ]
     60       },
     61       hljs.COMMENT(
     62         '%',
     63         '$',
     64         {
     65           relevance: 0
     66         }
     67       )
     68     ]
     69   };
     70 }
     71 
     72 module.exports = latex;