l0bsterssg

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

asciidoc.js (4601B)


      1 /*
      2 Language: AsciiDoc
      3 Requires: xml.js
      4 Author: Dan Allen <dan.j.allen@gmail.com>
      5 Website: http://asciidoc.org
      6 Description: A semantic, text-based document format that can be exported to HTML, DocBook and other backends.
      7 Category: markup
      8 */
      9 
     10 /** @type LanguageFn */
     11 function asciidoc(hljs) {
     12   return {
     13     name: 'AsciiDoc',
     14     aliases: ['adoc'],
     15     contains: [
     16       // block comment
     17       hljs.COMMENT(
     18         '^/{4,}\\n',
     19         '\\n/{4,}$',
     20         // can also be done as...
     21         //'^/{4,}$',
     22         //'^/{4,}$',
     23         {
     24           relevance: 10
     25         }
     26       ),
     27       // line comment
     28       hljs.COMMENT(
     29         '^//',
     30         '$',
     31         {
     32           relevance: 0
     33         }
     34       ),
     35       // title
     36       {
     37         className: 'title',
     38         begin: '^\\.\\w.*$'
     39       },
     40       // example, admonition & sidebar blocks
     41       {
     42         begin: '^[=\\*]{4,}\\n',
     43         end: '\\n^[=\\*]{4,}$',
     44         relevance: 10
     45       },
     46       // headings
     47       {
     48         className: 'section',
     49         relevance: 10,
     50         variants: [
     51           {begin: '^(={1,5}) .+?( \\1)?$'},
     52           {begin: '^[^\\[\\]\\n]+?\\n[=\\-~\\^\\+]{2,}$'},
     53         ]
     54       },
     55       // document attributes
     56       {
     57         className: 'meta',
     58         begin: '^:.+?:',
     59         end: '\\s',
     60         excludeEnd: true,
     61         relevance: 10
     62       },
     63       // block attributes
     64       {
     65         className: 'meta',
     66         begin: '^\\[.+?\\]$',
     67         relevance: 0
     68       },
     69       // quoteblocks
     70       {
     71         className: 'quote',
     72         begin: '^_{4,}\\n',
     73         end: '\\n_{4,}$',
     74         relevance: 10
     75       },
     76       // listing and literal blocks
     77       {
     78         className: 'code',
     79         begin: '^[\\-\\.]{4,}\\n',
     80         end: '\\n[\\-\\.]{4,}$',
     81         relevance: 10
     82       },
     83       // passthrough blocks
     84       {
     85         begin: '^\\+{4,}\\n',
     86         end: '\\n\\+{4,}$',
     87         contains: [
     88           {
     89             begin: '<', end: '>',
     90             subLanguage: 'xml',
     91             relevance: 0
     92           }
     93         ],
     94         relevance: 10
     95       },
     96       // lists (can only capture indicators)
     97       {
     98         className: 'bullet',
     99         begin: '^(\\*+|\\-+|\\.+|[^\\n]+?::)\\s+'
    100       },
    101       // admonition
    102       {
    103         className: 'symbol',
    104         begin: '^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+',
    105         relevance: 10
    106       },
    107       // inline strong
    108       {
    109         className: 'strong',
    110         // must not follow a word character or be followed by an asterisk or space
    111         begin: '\\B\\*(?![\\*\\s])',
    112         end: '(\\n{2}|\\*)',
    113         // allow escaped asterisk followed by word char
    114         contains: [
    115           {
    116             begin: '\\\\*\\w',
    117             relevance: 0
    118           }
    119         ]
    120       },
    121       // inline emphasis
    122       {
    123         className: 'emphasis',
    124         // must not follow a word character or be followed by a single quote or space
    125         begin: '\\B\'(?![\'\\s])',
    126         end: '(\\n{2}|\')',
    127         // allow escaped single quote followed by word char
    128         contains: [
    129           {
    130             begin: '\\\\\'\\w',
    131             relevance: 0
    132           }
    133         ],
    134         relevance: 0
    135       },
    136       // inline emphasis (alt)
    137       {
    138         className: 'emphasis',
    139         // must not follow a word character or be followed by an underline or space
    140         begin: '_(?![_\\s])',
    141         end: '(\\n{2}|_)',
    142         relevance: 0
    143       },
    144       // inline smart quotes
    145       {
    146         className: 'string',
    147         variants: [
    148           {begin: "``.+?''"},
    149           {begin: "`.+?'"}
    150         ]
    151       },
    152       // inline code snippets (TODO should get same treatment as strong and emphasis)
    153       {
    154         className: 'code',
    155         begin: '(`.+?`|\\+.+?\\+)',
    156         relevance: 0
    157       },
    158       // indented literal block
    159       {
    160         className: 'code',
    161         begin: '^[ \\t]',
    162         end: '$',
    163         relevance: 0
    164       },
    165       // horizontal rules
    166       {
    167         begin: '^\'{3,}[ \\t]*$',
    168         relevance: 10
    169       },
    170       // images and links
    171       {
    172         begin: '(link:)?(http|https|ftp|file|irc|image:?):\\S+\\[.*?\\]',
    173         returnBegin: true,
    174         contains: [
    175           {
    176             begin: '(link|image:?):',
    177             relevance: 0
    178           },
    179           {
    180             className: 'link',
    181             begin: '\\w',
    182             end: '[^\\[]+',
    183             relevance: 0
    184           },
    185           {
    186             className: 'string',
    187             begin: '\\[',
    188             end: '\\]',
    189             excludeBegin: true,
    190             excludeEnd: true,
    191             relevance: 0
    192           }
    193         ],
    194         relevance: 10
    195       }
    196     ]
    197   };
    198 }
    199 
    200 module.exports = asciidoc;