prism-sass.js 1.6 KB

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