prism-scss.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Prism.languages.scss = Prism.languages.extend('css', {
  2. 'comment': {
  3. pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
  4. lookbehind: true
  5. },
  6. 'atrule': {
  7. pattern: /@[\w-]+(?:\([^()]+\)|[^(])*?(?=\s+[{;])/,
  8. inside: {
  9. 'rule': /@[\w-]+/
  10. // See rest below
  11. }
  12. },
  13. // url, compassified
  14. 'url': /(?:[-a-z]+-)?url(?=\()/i,
  15. // CSS selector regex is not appropriate for Sass
  16. // since there can be lot more things (var, @ directive, nesting..)
  17. // a selector must start at the end of a property or after a brace (end of other rules or nesting)
  18. // it can contain some characters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
  19. // the end of a selector is found when there is no rules in it ( {} or {\s}) or if there is a property (because an interpolated var
  20. // can "pass" as a selector- e.g: proper#{$erty})
  21. // this one was hard to do, so please be careful if you edit this one :)
  22. 'selector': {
  23. // Initial look-ahead is used to prevent matching of blank selectors
  24. pattern: /(?=\S)[^@;{}()]?(?:[^@;{}()]|#\{\$[-\w]+\})+(?=\s*\{(?:\}|\s|[^}]+[:{][^}]+))/m,
  25. inside: {
  26. 'parent': {
  27. pattern: /&/,
  28. alias: 'important'
  29. },
  30. 'placeholder': /%[-\w]+/,
  31. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  32. }
  33. },
  34. 'property': {
  35. pattern: /(?:[\w-]|\$[-\w]+|#\{\$[-\w]+\})+(?=\s*:)/,
  36. inside: {
  37. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  38. }
  39. }
  40. });
  41. Prism.languages.insertBefore('scss', 'atrule', {
  42. 'keyword': [
  43. /@(?:if|else(?: if)?|for|each|while|import|extend|debug|warn|mixin|include|function|return|content)/i,
  44. {
  45. pattern: /( +)(?:from|through)(?= )/,
  46. lookbehind: true
  47. }
  48. ]
  49. });
  50. Prism.languages.insertBefore('scss', 'important', {
  51. // var and interpolated vars
  52. 'variable': /\$[-\w]+|#\{\$[-\w]+\}/
  53. });
  54. Prism.languages.insertBefore('scss', 'function', {
  55. 'placeholder': {
  56. pattern: /%[-\w]+/,
  57. alias: 'selector'
  58. },
  59. 'statement': {
  60. pattern: /\B!(?:default|optional)\b/i,
  61. alias: 'keyword'
  62. },
  63. 'boolean': /\b(?:true|false)\b/,
  64. 'null': {
  65. pattern: /\bnull\b/,
  66. alias: 'keyword'
  67. },
  68. 'operator': {
  69. pattern: /(\s)(?:[-+*\/%]|[=!]=|<=?|>=?|and|or|not)(?=\s)/,
  70. lookbehind: true
  71. }
  72. });
  73. Prism.languages.scss['atrule'].inside.rest = Prism.languages.scss;