UNPKG

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