prism-less.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* FIXME :
  2. :extend() is not handled specifically : its highlighting is buggy.
  3. Mixin usage must be inside a ruleset to be highlighted.
  4. At-rules (e.g. import) containing interpolations are buggy.
  5. Detached rulesets are highlighted as at-rules.
  6. A comment before a mixin usage prevents the latter to be properly highlighted.
  7. */
  8. Prism.languages.less = Prism.languages.extend('css', {
  9. 'comment': [
  10. /\/\*[\w\W]*?\*\//,
  11. {
  12. pattern: /(^|[^\\])\/\/.*/,
  13. lookbehind: true
  14. }
  15. ],
  16. 'atrule': {
  17. pattern: /@[\w-]+?(?:\([^{}]+\)|[^(){};])*?(?=\s*\{)/i,
  18. inside: {
  19. 'punctuation': /[:()]/
  20. }
  21. },
  22. // selectors and mixins are considered the same
  23. 'selector': {
  24. pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\([^{}]*\)|[^{};@])*?(?=\s*\{)/,
  25. inside: {
  26. // mixin parameters
  27. 'variable': /@+[\w-]+/
  28. }
  29. },
  30. 'property': /(\b|\B)(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/i,
  31. 'punctuation': /[{}();:,]/,
  32. 'operator': /[+\-*\/]/
  33. });
  34. // Invert function and punctuation positions
  35. Prism.languages.insertBefore('less', 'punctuation', {
  36. 'function': Prism.languages.less.function
  37. });
  38. Prism.languages.insertBefore('less', 'property', {
  39. 'variable': [
  40. // Variable declaration (the colon must be consumed!)
  41. {
  42. pattern: /@[\w-]+\s*:/,
  43. inside: {
  44. "punctuation": /:/
  45. }
  46. },
  47. // Variable usage
  48. /@@?[\w-]+/
  49. ],
  50. 'mixin-usage': {
  51. pattern: /([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,
  52. lookbehind: true,
  53. alias: 'function'
  54. }
  55. });