UNPKG

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