l0bsterssg

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

stylus.js (8699B)


      1 /*
      2 Language: Stylus
      3 Author: Bryant Williams <b.n.williams@gmail.com>
      4 Description: Stylus is an expressive, robust, feature-rich CSS language built for nodejs.
      5 Website: https://github.com/stylus/stylus
      6 Category: css
      7 */
      8 
      9 function stylus(hljs) {
     10 
     11   var VARIABLE = {
     12     className: 'variable',
     13     begin: '\\$' + hljs.IDENT_RE
     14   };
     15 
     16   var HEX_COLOR = {
     17     className: 'number',
     18     begin: '#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})'
     19   };
     20 
     21   var AT_KEYWORDS = [
     22     'charset',
     23     'css',
     24     'debug',
     25     'extend',
     26     'font-face',
     27     'for',
     28     'import',
     29     'include',
     30     'media',
     31     'mixin',
     32     'page',
     33     'warn',
     34     'while'
     35   ];
     36 
     37   var PSEUDO_SELECTORS = [
     38     'after',
     39     'before',
     40     'first-letter',
     41     'first-line',
     42     'active',
     43     'first-child',
     44     'focus',
     45     'hover',
     46     'lang',
     47     'link',
     48     'visited'
     49   ];
     50 
     51   var TAGS = [
     52     'a',
     53     'abbr',
     54     'address',
     55     'article',
     56     'aside',
     57     'audio',
     58     'b',
     59     'blockquote',
     60     'body',
     61     'button',
     62     'canvas',
     63     'caption',
     64     'cite',
     65     'code',
     66     'dd',
     67     'del',
     68     'details',
     69     'dfn',
     70     'div',
     71     'dl',
     72     'dt',
     73     'em',
     74     'fieldset',
     75     'figcaption',
     76     'figure',
     77     'footer',
     78     'form',
     79     'h1',
     80     'h2',
     81     'h3',
     82     'h4',
     83     'h5',
     84     'h6',
     85     'header',
     86     'hgroup',
     87     'html',
     88     'i',
     89     'iframe',
     90     'img',
     91     'input',
     92     'ins',
     93     'kbd',
     94     'label',
     95     'legend',
     96     'li',
     97     'mark',
     98     'menu',
     99     'nav',
    100     'object',
    101     'ol',
    102     'p',
    103     'q',
    104     'quote',
    105     'samp',
    106     'section',
    107     'span',
    108     'strong',
    109     'summary',
    110     'sup',
    111     'table',
    112     'tbody',
    113     'td',
    114     'textarea',
    115     'tfoot',
    116     'th',
    117     'thead',
    118     'time',
    119     'tr',
    120     'ul',
    121     'var',
    122     'video'
    123   ];
    124 
    125   var LOOKAHEAD_TAG_END = '(?=[\\.\\s\\n\\[\\:,])';
    126 
    127   var ATTRIBUTES = [
    128     'align-content',
    129     'align-items',
    130     'align-self',
    131     'animation',
    132     'animation-delay',
    133     'animation-direction',
    134     'animation-duration',
    135     'animation-fill-mode',
    136     'animation-iteration-count',
    137     'animation-name',
    138     'animation-play-state',
    139     'animation-timing-function',
    140     'auto',
    141     'backface-visibility',
    142     'background',
    143     'background-attachment',
    144     'background-clip',
    145     'background-color',
    146     'background-image',
    147     'background-origin',
    148     'background-position',
    149     'background-repeat',
    150     'background-size',
    151     'border',
    152     'border-bottom',
    153     'border-bottom-color',
    154     'border-bottom-left-radius',
    155     'border-bottom-right-radius',
    156     'border-bottom-style',
    157     'border-bottom-width',
    158     'border-collapse',
    159     'border-color',
    160     'border-image',
    161     'border-image-outset',
    162     'border-image-repeat',
    163     'border-image-slice',
    164     'border-image-source',
    165     'border-image-width',
    166     'border-left',
    167     'border-left-color',
    168     'border-left-style',
    169     'border-left-width',
    170     'border-radius',
    171     'border-right',
    172     'border-right-color',
    173     'border-right-style',
    174     'border-right-width',
    175     'border-spacing',
    176     'border-style',
    177     'border-top',
    178     'border-top-color',
    179     'border-top-left-radius',
    180     'border-top-right-radius',
    181     'border-top-style',
    182     'border-top-width',
    183     'border-width',
    184     'bottom',
    185     'box-decoration-break',
    186     'box-shadow',
    187     'box-sizing',
    188     'break-after',
    189     'break-before',
    190     'break-inside',
    191     'caption-side',
    192     'clear',
    193     'clip',
    194     'clip-path',
    195     'color',
    196     'column-count',
    197     'column-fill',
    198     'column-gap',
    199     'column-rule',
    200     'column-rule-color',
    201     'column-rule-style',
    202     'column-rule-width',
    203     'column-span',
    204     'column-width',
    205     'columns',
    206     'content',
    207     'counter-increment',
    208     'counter-reset',
    209     'cursor',
    210     'direction',
    211     'display',
    212     'empty-cells',
    213     'filter',
    214     'flex',
    215     'flex-basis',
    216     'flex-direction',
    217     'flex-flow',
    218     'flex-grow',
    219     'flex-shrink',
    220     'flex-wrap',
    221     'float',
    222     'font',
    223     'font-family',
    224     'font-feature-settings',
    225     'font-kerning',
    226     'font-language-override',
    227     'font-size',
    228     'font-size-adjust',
    229     'font-stretch',
    230     'font-style',
    231     'font-variant',
    232     'font-variant-ligatures',
    233     'font-weight',
    234     'height',
    235     'hyphens',
    236     'icon',
    237     'image-orientation',
    238     'image-rendering',
    239     'image-resolution',
    240     'ime-mode',
    241     'inherit',
    242     'initial',
    243     'justify-content',
    244     'left',
    245     'letter-spacing',
    246     'line-height',
    247     'list-style',
    248     'list-style-image',
    249     'list-style-position',
    250     'list-style-type',
    251     'margin',
    252     'margin-bottom',
    253     'margin-left',
    254     'margin-right',
    255     'margin-top',
    256     'marks',
    257     'mask',
    258     'max-height',
    259     'max-width',
    260     'min-height',
    261     'min-width',
    262     'nav-down',
    263     'nav-index',
    264     'nav-left',
    265     'nav-right',
    266     'nav-up',
    267     'none',
    268     'normal',
    269     'object-fit',
    270     'object-position',
    271     'opacity',
    272     'order',
    273     'orphans',
    274     'outline',
    275     'outline-color',
    276     'outline-offset',
    277     'outline-style',
    278     'outline-width',
    279     'overflow',
    280     'overflow-wrap',
    281     'overflow-x',
    282     'overflow-y',
    283     'padding',
    284     'padding-bottom',
    285     'padding-left',
    286     'padding-right',
    287     'padding-top',
    288     'page-break-after',
    289     'page-break-before',
    290     'page-break-inside',
    291     'perspective',
    292     'perspective-origin',
    293     'pointer-events',
    294     'position',
    295     'quotes',
    296     'resize',
    297     'right',
    298     'tab-size',
    299     'table-layout',
    300     'text-align',
    301     'text-align-last',
    302     'text-decoration',
    303     'text-decoration-color',
    304     'text-decoration-line',
    305     'text-decoration-style',
    306     'text-indent',
    307     'text-overflow',
    308     'text-rendering',
    309     'text-shadow',
    310     'text-transform',
    311     'text-underline-position',
    312     'top',
    313     'transform',
    314     'transform-origin',
    315     'transform-style',
    316     'transition',
    317     'transition-delay',
    318     'transition-duration',
    319     'transition-property',
    320     'transition-timing-function',
    321     'unicode-bidi',
    322     'vertical-align',
    323     'visibility',
    324     'white-space',
    325     'widows',
    326     'width',
    327     'word-break',
    328     'word-spacing',
    329     'word-wrap',
    330     'z-index'
    331   ];
    332 
    333   // illegals
    334   var ILLEGAL = [
    335     '\\?',
    336     '(\\bReturn\\b)', // monkey
    337     '(\\bEnd\\b)', // monkey
    338     '(\\bend\\b)', // vbscript
    339     '(\\bdef\\b)', // gradle
    340     ';', // a whole lot of languages
    341     '#\\s', // markdown
    342     '\\*\\s', // markdown
    343     '===\\s', // markdown
    344     '\\|',
    345     '%', // prolog
    346   ];
    347 
    348   return {
    349     name: 'Stylus',
    350     aliases: ['styl'],
    351     case_insensitive: false,
    352     keywords: 'if else for in',
    353     illegal: '(' + ILLEGAL.join('|') + ')',
    354     contains: [
    355 
    356       // strings
    357       hljs.QUOTE_STRING_MODE,
    358       hljs.APOS_STRING_MODE,
    359 
    360       // comments
    361       hljs.C_LINE_COMMENT_MODE,
    362       hljs.C_BLOCK_COMMENT_MODE,
    363 
    364       // hex colors
    365       HEX_COLOR,
    366 
    367       // class tag
    368       {
    369         begin: '\\.[a-zA-Z][a-zA-Z0-9_-]*' + LOOKAHEAD_TAG_END,
    370         className: 'selector-class'
    371       },
    372 
    373       // id tag
    374       {
    375         begin: '\\#[a-zA-Z][a-zA-Z0-9_-]*' + LOOKAHEAD_TAG_END,
    376         className: 'selector-id'
    377       },
    378 
    379       // tags
    380       {
    381         begin: '\\b(' + TAGS.join('|') + ')' + LOOKAHEAD_TAG_END,
    382         className: 'selector-tag'
    383       },
    384 
    385       // psuedo selectors
    386       {
    387         begin: '&?:?:\\b(' + PSEUDO_SELECTORS.join('|') + ')' + LOOKAHEAD_TAG_END
    388       },
    389 
    390       // @ keywords
    391       {
    392         begin: '\@(' + AT_KEYWORDS.join('|') + ')\\b'
    393       },
    394 
    395       // variables
    396       VARIABLE,
    397 
    398       // dimension
    399       hljs.CSS_NUMBER_MODE,
    400 
    401       // number
    402       hljs.NUMBER_MODE,
    403 
    404       // functions
    405       //  - only from beginning of line + whitespace
    406       {
    407         className: 'function',
    408         begin: '^[a-zA-Z][a-zA-Z0-9_\-]*\\(.*\\)',
    409         illegal: '[\\n]',
    410         returnBegin: true,
    411         contains: [
    412           {className: 'title', begin: '\\b[a-zA-Z][a-zA-Z0-9_\-]*'},
    413           {
    414             className: 'params',
    415             begin: /\(/,
    416             end: /\)/,
    417             contains: [
    418               HEX_COLOR,
    419               VARIABLE,
    420               hljs.APOS_STRING_MODE,
    421               hljs.CSS_NUMBER_MODE,
    422               hljs.NUMBER_MODE,
    423               hljs.QUOTE_STRING_MODE
    424             ]
    425           }
    426         ]
    427       },
    428 
    429       // attributes
    430       //  - only from beginning of line + whitespace
    431       //  - must have whitespace after it
    432       {
    433         className: 'attribute',
    434         begin: '\\b(' + ATTRIBUTES.reverse().join('|') + ')\\b',
    435         starts: {
    436           // value container
    437           end: /;|$/,
    438           contains: [
    439             HEX_COLOR,
    440             VARIABLE,
    441             hljs.APOS_STRING_MODE,
    442             hljs.QUOTE_STRING_MODE,
    443             hljs.CSS_NUMBER_MODE,
    444             hljs.NUMBER_MODE,
    445             hljs.C_BLOCK_COMMENT_MODE
    446           ],
    447           illegal: /\./,
    448           relevance: 0
    449         }
    450       }
    451     ]
    452   };
    453 }
    454 
    455 module.exports = stylus;