scss.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. module.exports = function(hljs) {
  2. var AT_IDENTIFIER = '@[a-z-]+' // @font-face
  3. var AT_MODIFIERS = "and or not only"
  4. var IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*';
  5. var VARIABLE = {
  6. className: 'variable',
  7. begin: '(\\$' + IDENT_RE + ')\\b'
  8. };
  9. var HEXCOLOR = {
  10. className: 'number', begin: '#[0-9A-Fa-f]+'
  11. };
  12. var DEF_INTERNALS = {
  13. className: 'attribute',
  14. begin: '[A-Z\\_\\.\\-]+', end: ':',
  15. excludeEnd: true,
  16. illegal: '[^\\s]',
  17. starts: {
  18. endsWithParent: true, excludeEnd: true,
  19. contains: [
  20. HEXCOLOR,
  21. hljs.CSS_NUMBER_MODE,
  22. hljs.QUOTE_STRING_MODE,
  23. hljs.APOS_STRING_MODE,
  24. hljs.C_BLOCK_COMMENT_MODE,
  25. {
  26. className: 'meta', begin: '!important'
  27. }
  28. ]
  29. }
  30. };
  31. return {
  32. case_insensitive: true,
  33. illegal: '[=/|\']',
  34. contains: [
  35. hljs.C_LINE_COMMENT_MODE,
  36. hljs.C_BLOCK_COMMENT_MODE,
  37. {
  38. className: 'selector-id', begin: '\\#[A-Za-z0-9_-]+',
  39. relevance: 0
  40. },
  41. {
  42. className: 'selector-class', begin: '\\.[A-Za-z0-9_-]+',
  43. relevance: 0
  44. },
  45. {
  46. className: 'selector-attr', begin: '\\[', end: '\\]',
  47. illegal: '$'
  48. },
  49. {
  50. className: 'selector-tag', // begin: IDENT_RE, end: '[,|\\s]'
  51. begin: '\\b(a|abbr|acronym|address|area|article|aside|audio|b|base|big|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|frame|frameset|(h[1-6])|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|map|mark|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|samp|script|section|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|ul|var|video)\\b',
  52. relevance: 0
  53. },
  54. {
  55. className: 'selector-pseudo',
  56. begin: ':(visited|valid|root|right|required|read-write|read-only|out-range|optional|only-of-type|only-child|nth-of-type|nth-last-of-type|nth-last-child|nth-child|not|link|left|last-of-type|last-child|lang|invalid|indeterminate|in-range|hover|focus|first-of-type|first-line|first-letter|first-child|first|enabled|empty|disabled|default|checked|before|after|active)'
  57. },
  58. {
  59. className: 'selector-pseudo',
  60. begin: '::(after|before|choices|first-letter|first-line|repeat-index|repeat-item|selection|value)'
  61. },
  62. VARIABLE,
  63. {
  64. className: 'attribute',
  65. begin: '\\b(src|z-index|word-wrap|word-spacing|word-break|width|widows|white-space|visibility|vertical-align|unicode-bidi|transition-timing-function|transition-property|transition-duration|transition-delay|transition|transform-style|transform-origin|transform|top|text-underline-position|text-transform|text-shadow|text-rendering|text-overflow|text-indent|text-decoration-style|text-decoration-line|text-decoration-color|text-decoration|text-align-last|text-align|tab-size|table-layout|right|resize|quotes|position|pointer-events|perspective-origin|perspective|page-break-inside|page-break-before|page-break-after|padding-top|padding-right|padding-left|padding-bottom|padding|overflow-y|overflow-x|overflow-wrap|overflow|outline-width|outline-style|outline-offset|outline-color|outline|orphans|order|opacity|object-position|object-fit|normal|none|nav-up|nav-right|nav-left|nav-index|nav-down|min-width|min-height|max-width|max-height|mask|marks|margin-top|margin-right|margin-left|margin-bottom|margin|list-style-type|list-style-position|list-style-image|list-style|line-height|letter-spacing|left|justify-content|initial|inherit|ime-mode|image-orientation|image-resolution|image-rendering|icon|hyphens|height|font-weight|font-variant-ligatures|font-variant|font-style|font-stretch|font-size-adjust|font-size|font-language-override|font-kerning|font-feature-settings|font-family|font|float|flex-wrap|flex-shrink|flex-grow|flex-flow|flex-direction|flex-basis|flex|filter|empty-cells|display|direction|cursor|counter-reset|counter-increment|content|column-width|column-span|column-rule-width|column-rule-style|column-rule-color|column-rule|column-gap|column-fill|column-count|columns|color|clip-path|clip|clear|caption-side|break-inside|break-before|break-after|box-sizing|box-shadow|box-decoration-break|bottom|border-width|border-top-width|border-top-style|border-top-right-radius|border-top-left-radius|border-top-color|border-top|border-style|border-spacing|border-right-width|border-right-style|border-right-color|border-right|border-radius|border-left-width|border-left-style|border-left-color|border-left|border-image-width|border-image-source|border-image-slice|border-image-repeat|border-image-outset|border-image|border-color|border-collapse|border-bottom-width|border-bottom-style|border-bottom-right-radius|border-bottom-left-radius|border-bottom-color|border-bottom|border|background-size|background-repeat|background-position|background-origin|background-image|background-color|background-clip|background-attachment|background-blend-mode|background|backface-visibility|auto|animation-timing-function|animation-play-state|animation-name|animation-iteration-count|animation-fill-mode|animation-duration|animation-direction|animation-delay|animation|align-self|align-items|align-content)\\b',
  66. illegal: '[^\\s]'
  67. },
  68. {
  69. begin: '\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b'
  70. },
  71. {
  72. begin: ':', end: ';',
  73. contains: [
  74. VARIABLE,
  75. HEXCOLOR,
  76. hljs.CSS_NUMBER_MODE,
  77. hljs.QUOTE_STRING_MODE,
  78. hljs.APOS_STRING_MODE,
  79. {
  80. className: 'meta', begin: '!important'
  81. }
  82. ]
  83. },
  84. // matching these here allows us to treat them more like regular CSS
  85. // rules so everything between the {} gets regular rule highlighting,
  86. // which is what we want for page and font-face
  87. {
  88. begin: '@(page|font-face)',
  89. lexemes: AT_IDENTIFIER,
  90. keywords: '@page @font-face'
  91. },
  92. {
  93. begin: '@', end: '[{;]',
  94. returnBegin: true,
  95. keywords: AT_MODIFIERS,
  96. contains: [
  97. {
  98. begin: AT_IDENTIFIER,
  99. className: "keyword"
  100. },
  101. VARIABLE,
  102. hljs.QUOTE_STRING_MODE,
  103. hljs.APOS_STRING_MODE,
  104. HEXCOLOR,
  105. hljs.CSS_NUMBER_MODE,
  106. // {
  107. // begin: '\\s[A-Za-z0-9_.-]+',
  108. // relevance: 0
  109. // }
  110. ]
  111. }
  112. ]
  113. };
  114. };