prism-less.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /\/\*[\s\S]*?\*\//,
  11. {
  12. pattern: /(^|[^\\])\/\/.*/,
  13. lookbehind: true
  14. }
  15. ],
  16. 'atrule': {
  17. pattern: /@[\w-](?:\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};\s]|\s+(?!\s))*?(?=\s*\{)/,
  18. inside: {
  19. 'punctuation': /[:()]/
  20. }
  21. },
  22. // selectors and mixins are considered the same
  23. 'selector': {
  24. pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\((?:[^(){}]|\([^(){}]*\))*\)|[^(){};@\s]|\s+(?!\s))*?(?=\s*\{)/,
  25. inside: {
  26. // mixin parameters
  27. 'variable': /@+[\w-]+/
  28. }
  29. },
  30. 'property': /(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/,
  31. 'operator': /[+\-*\/]/
  32. });
  33. Prism.languages.insertBefore('less', 'property', {
  34. 'variable': [
  35. // Variable declaration (the colon must be consumed!)
  36. {
  37. pattern: /@[\w-]+\s*:/,
  38. inside: {
  39. 'punctuation': /:/
  40. }
  41. },
  42. // Variable usage
  43. /@@?[\w-]+/
  44. ],
  45. 'mixin-usage': {
  46. pattern: /([{;]\s*)[.#](?!\d)[\w-].*?(?=[(;])/,
  47. lookbehind: true,
  48. alias: 'function'
  49. }
  50. });