1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = stylus
|
---|
4 | stylus.displayName = 'stylus'
|
---|
5 | stylus.aliases = []
|
---|
6 | function stylus(Prism) {
|
---|
7 | ;(function (Prism) {
|
---|
8 | var unit = {
|
---|
9 | pattern: /(\b\d+)(?:%|[a-z]+)/,
|
---|
10 | lookbehind: true
|
---|
11 | } // 123 -123 .123 -.123 12.3 -12.3
|
---|
12 | var number = {
|
---|
13 | pattern: /(^|[^\w.-])-?(?:\d+(?:\.\d+)?|\.\d+)/,
|
---|
14 | lookbehind: true
|
---|
15 | }
|
---|
16 | var inside = {
|
---|
17 | comment: {
|
---|
18 | pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
|
---|
19 | lookbehind: true
|
---|
20 | },
|
---|
21 | url: {
|
---|
22 | pattern: /\burl\((["']?).*?\1\)/i,
|
---|
23 | greedy: true
|
---|
24 | },
|
---|
25 | string: {
|
---|
26 | pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
|
---|
27 | greedy: true
|
---|
28 | },
|
---|
29 | interpolation: null,
|
---|
30 | // See below
|
---|
31 | func: null,
|
---|
32 | // See below
|
---|
33 | important: /\B!(?:important|optional)\b/i,
|
---|
34 | keyword: {
|
---|
35 | pattern: /(^|\s+)(?:(?:else|for|if|return|unless)(?=\s|$)|@[\w-]+)/,
|
---|
36 | lookbehind: true
|
---|
37 | },
|
---|
38 | hexcode: /#[\da-f]{3,6}/i,
|
---|
39 | color: [
|
---|
40 | /\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i,
|
---|
41 | {
|
---|
42 | pattern:
|
---|
43 | /\b(?:hsl|rgb)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:hsl|rgb)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,
|
---|
44 | inside: {
|
---|
45 | unit: unit,
|
---|
46 | number: number,
|
---|
47 | function: /[\w-]+(?=\()/,
|
---|
48 | punctuation: /[(),]/
|
---|
49 | }
|
---|
50 | }
|
---|
51 | ],
|
---|
52 | entity: /\\[\da-f]{1,8}/i,
|
---|
53 | unit: unit,
|
---|
54 | boolean: /\b(?:false|true)\b/,
|
---|
55 | operator: [
|
---|
56 | // We want non-word chars around "-" because it is
|
---|
57 | // accepted in property names.
|
---|
58 | /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/
|
---|
59 | ],
|
---|
60 | number: number,
|
---|
61 | punctuation: /[{}()\[\];:,]/
|
---|
62 | }
|
---|
63 | inside['interpolation'] = {
|
---|
64 | pattern: /\{[^\r\n}:]+\}/,
|
---|
65 | alias: 'variable',
|
---|
66 | inside: {
|
---|
67 | delimiter: {
|
---|
68 | pattern: /^\{|\}$/,
|
---|
69 | alias: 'punctuation'
|
---|
70 | },
|
---|
71 | rest: inside
|
---|
72 | }
|
---|
73 | }
|
---|
74 | inside['func'] = {
|
---|
75 | pattern: /[\w-]+\([^)]*\).*/,
|
---|
76 | inside: {
|
---|
77 | function: /^[^(]+/,
|
---|
78 | rest: inside
|
---|
79 | }
|
---|
80 | }
|
---|
81 | Prism.languages.stylus = {
|
---|
82 | 'atrule-declaration': {
|
---|
83 | pattern: /(^[ \t]*)@.+/m,
|
---|
84 | lookbehind: true,
|
---|
85 | inside: {
|
---|
86 | atrule: /^@[\w-]+/,
|
---|
87 | rest: inside
|
---|
88 | }
|
---|
89 | },
|
---|
90 | 'variable-declaration': {
|
---|
91 | pattern: /(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:\{[^{}]*\}|\S.*|$)/m,
|
---|
92 | lookbehind: true,
|
---|
93 | inside: {
|
---|
94 | variable: /^\S+/,
|
---|
95 | rest: inside
|
---|
96 | }
|
---|
97 | },
|
---|
98 | statement: {
|
---|
99 | pattern: /(^[ \t]*)(?:else|for|if|return|unless)[ \t].+/m,
|
---|
100 | lookbehind: true,
|
---|
101 | inside: {
|
---|
102 | keyword: /^\S+/,
|
---|
103 | rest: inside
|
---|
104 | }
|
---|
105 | },
|
---|
106 | // A property/value pair cannot end with a comma or a brace
|
---|
107 | // It cannot have indented content unless it ended with a semicolon
|
---|
108 | 'property-declaration': {
|
---|
109 | pattern:
|
---|
110 | /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)(?!\s)[^{\r\n]*(?:;|[^{\r\n,]$(?!(?:\r?\n|\r)(?:\{|\2[ \t])))/m,
|
---|
111 | lookbehind: true,
|
---|
112 | inside: {
|
---|
113 | property: {
|
---|
114 | pattern: /^[^\s:]+/,
|
---|
115 | inside: {
|
---|
116 | interpolation: inside.interpolation
|
---|
117 | }
|
---|
118 | },
|
---|
119 | rest: inside
|
---|
120 | }
|
---|
121 | },
|
---|
122 | // A selector can contain parentheses only as part of a pseudo-element
|
---|
123 | // It can span multiple lines.
|
---|
124 | // It must end with a comma or an accolade or have indented content.
|
---|
125 | selector: {
|
---|
126 | pattern:
|
---|
127 | /(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\)|(?![\w-]))|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t])))/m,
|
---|
128 | lookbehind: true,
|
---|
129 | inside: {
|
---|
130 | interpolation: inside.interpolation,
|
---|
131 | comment: inside.comment,
|
---|
132 | punctuation: /[{},]/
|
---|
133 | }
|
---|
134 | },
|
---|
135 | func: inside.func,
|
---|
136 | string: inside.string,
|
---|
137 | comment: {
|
---|
138 | pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
|
---|
139 | lookbehind: true,
|
---|
140 | greedy: true
|
---|
141 | },
|
---|
142 | interpolation: inside.interpolation,
|
---|
143 | punctuation: /[{}()\[\];:.]/
|
---|
144 | }
|
---|
145 | })(Prism)
|
---|
146 | }
|
---|