prism-sass.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. (function (Prism) {
  2. Prism.languages.sass = Prism.languages.extend('css', {
  3. // Sass comments don't need to be closed, only indented
  4. 'comment': {
  5. pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t].+)*/m,
  6. lookbehind: true,
  7. greedy: true
  8. }
  9. });
  10. Prism.languages.insertBefore('sass', 'atrule', {
  11. // We want to consume the whole line
  12. 'atrule-line': {
  13. // Includes support for = and + shortcuts
  14. pattern: /^(?:[ \t]*)[@+=].+/m,
  15. greedy: true,
  16. inside: {
  17. 'atrule': /(?:@[\w-]+|[+=])/
  18. }
  19. }
  20. });
  21. delete Prism.languages.sass.atrule;
  22. var variable = /\$[-\w]+|#\{\$[-\w]+\}/;
  23. var operator = [
  24. /[+*\/%]|[=!]=|<=?|>=?|\b(?:and|not|or)\b/,
  25. {
  26. pattern: /(\s)-(?=\s)/,
  27. lookbehind: true
  28. }
  29. ];
  30. Prism.languages.insertBefore('sass', 'property', {
  31. // We want to consume the whole line
  32. 'variable-line': {
  33. pattern: /^[ \t]*\$.+/m,
  34. greedy: true,
  35. inside: {
  36. 'punctuation': /:/,
  37. 'variable': variable,
  38. 'operator': operator
  39. }
  40. },
  41. // We want to consume the whole line
  42. 'property-line': {
  43. pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s].*)/m,
  44. greedy: true,
  45. inside: {
  46. 'property': [
  47. /[^:\s]+(?=\s*:)/,
  48. {
  49. pattern: /(:)[^:\s]+/,
  50. lookbehind: true
  51. }
  52. ],
  53. 'punctuation': /:/,
  54. 'variable': variable,
  55. 'operator': operator,
  56. 'important': Prism.languages.sass.important
  57. }
  58. }
  59. });
  60. delete Prism.languages.sass.property;
  61. delete Prism.languages.sass.important;
  62. // Now that whole lines for other patterns are consumed,
  63. // what's left should be selectors
  64. Prism.languages.insertBefore('sass', 'punctuation', {
  65. 'selector': {
  66. pattern: /^([ \t]*)\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,[^,\r\n]+|[^,\r\n]*)(?:,[^,\r\n]+)*)*/m,
  67. lookbehind: true,
  68. greedy: true
  69. }
  70. });
  71. }(Prism));