l0bsterssg

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

css.js (3479B)


      1 /*
      2 Language: CSS
      3 Category: common, css
      4 Website: https://developer.mozilla.org/en-US/docs/Web/CSS
      5 */
      6 
      7 /** @type LanguageFn */
      8 function css(hljs) {
      9   var FUNCTION_LIKE = {
     10     begin: /[\w-]+\(/, returnBegin: true,
     11     contains: [
     12       {
     13         className: 'built_in',
     14         begin: /[\w-]+/
     15       },
     16       {
     17         begin: /\(/, end: /\)/,
     18         contains: [
     19           hljs.APOS_STRING_MODE,
     20           hljs.QUOTE_STRING_MODE,
     21           hljs.CSS_NUMBER_MODE,
     22         ]
     23       }
     24     ]
     25   };
     26   var ATTRIBUTE = {
     27     className: 'attribute',
     28     begin: /\S/, end: ':', excludeEnd: true,
     29     starts: {
     30       endsWithParent: true, excludeEnd: true,
     31       contains: [
     32         FUNCTION_LIKE,
     33         hljs.CSS_NUMBER_MODE,
     34         hljs.QUOTE_STRING_MODE,
     35         hljs.APOS_STRING_MODE,
     36         hljs.C_BLOCK_COMMENT_MODE,
     37         {
     38           className: 'number', begin: '#[0-9A-Fa-f]+'
     39         },
     40         {
     41           className: 'meta', begin: '!important'
     42         }
     43       ]
     44     }
     45   };
     46   var AT_IDENTIFIER = '@[a-z-]+'; // @font-face
     47   var AT_MODIFIERS = "and or not only";
     48   var AT_PROPERTY_RE = /@\-?\w[\w]*(\-\w+)*/; // @-webkit-keyframes
     49   var IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*';
     50   var RULE = {
     51     begin: /(?:[A-Z\_\.\-]+|--[a-zA-Z0-9_-]+)\s*:/, returnBegin: true, end: ';', endsWithParent: true,
     52     contains: [
     53       ATTRIBUTE
     54     ]
     55   };
     56 
     57   return {
     58     name: 'CSS',
     59     case_insensitive: true,
     60     illegal: /[=\/|'\$]/,
     61     contains: [
     62       hljs.C_BLOCK_COMMENT_MODE,
     63       {
     64         className: 'selector-id', begin: /#[A-Za-z0-9_-]+/
     65       },
     66       {
     67         className: 'selector-class', begin: /\.[A-Za-z0-9_-]+/
     68       },
     69       {
     70         className: 'selector-attr',
     71         begin: /\[/, end: /\]/,
     72         illegal: '$',
     73         contains: [
     74           hljs.APOS_STRING_MODE,
     75           hljs.QUOTE_STRING_MODE,
     76         ]
     77       },
     78       {
     79         className: 'selector-pseudo',
     80         begin: /:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/
     81       },
     82       // matching these here allows us to treat them more like regular CSS
     83       // rules so everything between the {} gets regular rule highlighting,
     84       // which is what we want for page and font-face
     85       {
     86         begin: '@(page|font-face)',
     87         lexemes: AT_IDENTIFIER,
     88         keywords: '@page @font-face'
     89       },
     90       {
     91         begin: '@', end: '[{;]', // at_rule eating first "{" is a good thing
     92                                  // because it doesn’t let it to be parsed as
     93                                  // a rule set but instead drops parser into
     94                                  // the default mode which is how it should be.
     95         illegal: /:/, // break on Less variables @var: ...
     96         returnBegin: true,
     97         contains: [
     98           {
     99             className: 'keyword',
    100             begin: AT_PROPERTY_RE
    101           },
    102           {
    103             begin: /\s/, endsWithParent: true, excludeEnd: true,
    104             relevance: 0,
    105             keywords: AT_MODIFIERS,
    106             contains: [
    107               {
    108                 begin: /[a-z-]+:/,
    109                 className:"attribute"
    110               },
    111               hljs.APOS_STRING_MODE,
    112               hljs.QUOTE_STRING_MODE,
    113               hljs.CSS_NUMBER_MODE
    114             ]
    115           }
    116         ]
    117       },
    118       {
    119         className: 'selector-tag', begin: IDENT_RE,
    120         relevance: 0
    121       },
    122       {
    123         begin: '{', end: '}',
    124         illegal: /\S/,
    125         contains: [
    126           hljs.C_BLOCK_COMMENT_MODE,
    127           RULE,
    128         ]
    129       }
    130     ]
    131   };
    132 }
    133 
    134 module.exports = css;