UNPKG

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