Commit | Line | Data |
---|---|---|
837afb80 TD |
1 | (function(mod) { |
2 | if (typeof exports == "object" && typeof module == "object") // CommonJS | |
3 | mod(require("../../lib/codemirror")); | |
4 | else if (typeof define == "function" && define.amd) // AMD | |
5 | define(["../../lib/codemirror"], mod); | |
6 | else // Plain browser env | |
7 | mod(CodeMirror); | |
8 | })(function(CodeMirror) { | |
9 | "use strict"; | |
77b7b761 | 10 | |
837afb80 TD |
11 | CodeMirror.defineMode("css", function(config, parserConfig) { |
12 | if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css"); | |
77b7b761 TD |
13 | |
14 | var indentUnit = config.indentUnit, | |
837afb80 TD |
15 | tokenHooks = parserConfig.tokenHooks, |
16 | mediaTypes = parserConfig.mediaTypes || {}, | |
17 | mediaFeatures = parserConfig.mediaFeatures || {}, | |
77b7b761 TD |
18 | propertyKeywords = parserConfig.propertyKeywords || {}, |
19 | colorKeywords = parserConfig.colorKeywords || {}, | |
20 | valueKeywords = parserConfig.valueKeywords || {}, | |
837afb80 TD |
21 | fontProperties = parserConfig.fontProperties || {}, |
22 | allowNested = parserConfig.allowNested; | |
77b7b761 | 23 | |
837afb80 | 24 | var type, override; |
77b7b761 TD |
25 | function ret(style, tp) { type = tp; return style; } |
26 | ||
837afb80 TD |
27 | // Tokenizers |
28 | ||
77b7b761 TD |
29 | function tokenBase(stream, state) { |
30 | var ch = stream.next(); | |
837afb80 TD |
31 | if (tokenHooks[ch]) { |
32 | var result = tokenHooks[ch](stream, state); | |
77b7b761 TD |
33 | if (result !== false) return result; |
34 | } | |
837afb80 TD |
35 | if (ch == "@") { |
36 | stream.eatWhile(/[\w\\\-]/); | |
37 | return ret("def", stream.current()); | |
38 | } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) { | |
39 | return ret(null, "compare"); | |
40 | } else if (ch == "\"" || ch == "'") { | |
77b7b761 TD |
41 | state.tokenize = tokenString(ch); |
42 | return state.tokenize(stream, state); | |
837afb80 | 43 | } else if (ch == "#") { |
77b7b761 TD |
44 | stream.eatWhile(/[\w\\\-]/); |
45 | return ret("atom", "hash"); | |
837afb80 | 46 | } else if (ch == "!") { |
77b7b761 TD |
47 | stream.match(/^\s*\w*/); |
48 | return ret("keyword", "important"); | |
837afb80 | 49 | } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) { |
77b7b761 TD |
50 | stream.eatWhile(/[\w.%]/); |
51 | return ret("number", "unit"); | |
837afb80 TD |
52 | } else if (ch === "-") { |
53 | if (/[\d.]/.test(stream.peek())) { | |
77b7b761 TD |
54 | stream.eatWhile(/[\w.%]/); |
55 | return ret("number", "unit"); | |
56 | } else if (stream.match(/^[^-]+-/)) { | |
57 | return ret("meta", "meta"); | |
58 | } | |
837afb80 | 59 | } else if (/[,+>*\/]/.test(ch)) { |
77b7b761 | 60 | return ret(null, "select-op"); |
837afb80 | 61 | } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) { |
77b7b761 | 62 | return ret("qualifier", "qualifier"); |
837afb80 | 63 | } else if (/[:;{}\[\]\(\)]/.test(ch)) { |
77b7b761 | 64 | return ret(null, ch); |
837afb80 | 65 | } else if (ch == "u" && stream.match("rl(")) { |
77b7b761 TD |
66 | stream.backUp(1); |
67 | state.tokenize = tokenParenthesized; | |
837afb80 TD |
68 | return ret("property", "word"); |
69 | } else if (/[\w\\\-]/.test(ch)) { | |
77b7b761 | 70 | stream.eatWhile(/[\w\\\-]/); |
837afb80 TD |
71 | return ret("property", "word"); |
72 | } else { | |
73 | return ret(null, null); | |
77b7b761 TD |
74 | } |
75 | } | |
76 | ||
837afb80 | 77 | function tokenString(quote) { |
77b7b761 TD |
78 | return function(stream, state) { |
79 | var escaped = false, ch; | |
80 | while ((ch = stream.next()) != null) { | |
837afb80 TD |
81 | if (ch == quote && !escaped) { |
82 | if (quote == ")") stream.backUp(1); | |
77b7b761 | 83 | break; |
837afb80 | 84 | } |
77b7b761 TD |
85 | escaped = !escaped && ch == "\\"; |
86 | } | |
837afb80 | 87 | if (ch == quote || !escaped && quote != ")") state.tokenize = null; |
77b7b761 TD |
88 | return ret("string", "string"); |
89 | }; | |
90 | } | |
91 | ||
92 | function tokenParenthesized(stream, state) { | |
93 | stream.next(); // Must be '(' | |
94 | if (!stream.match(/\s*[\"\']/, false)) | |
837afb80 | 95 | state.tokenize = tokenString(")"); |
77b7b761 | 96 | else |
837afb80 | 97 | state.tokenize = null; |
77b7b761 TD |
98 | return ret(null, "("); |
99 | } | |
100 | ||
837afb80 TD |
101 | // Context management |
102 | ||
103 | function Context(type, indent, prev) { | |
104 | this.type = type; | |
105 | this.indent = indent; | |
106 | this.prev = prev; | |
107 | } | |
108 | ||
109 | function pushContext(state, stream, type) { | |
110 | state.context = new Context(type, stream.indentation() + indentUnit, state.context); | |
111 | return type; | |
112 | } | |
113 | ||
114 | function popContext(state) { | |
115 | state.context = state.context.prev; | |
116 | return state.context.type; | |
117 | } | |
118 | ||
119 | function pass(type, stream, state) { | |
120 | return states[state.context.type](type, stream, state); | |
121 | } | |
122 | function popAndPass(type, stream, state, n) { | |
123 | for (var i = n || 1; i > 0; i--) | |
124 | state.context = state.context.prev; | |
125 | return pass(type, stream, state); | |
126 | } | |
127 | ||
128 | // Parser | |
129 | ||
130 | function wordAsValue(stream) { | |
131 | var word = stream.current().toLowerCase(); | |
132 | if (valueKeywords.hasOwnProperty(word)) | |
133 | override = "atom"; | |
134 | else if (colorKeywords.hasOwnProperty(word)) | |
135 | override = "keyword"; | |
136 | else | |
137 | override = "variable"; | |
138 | } | |
139 | ||
140 | var states = {}; | |
141 | ||
142 | states.top = function(type, stream, state) { | |
143 | if (type == "{") { | |
144 | return pushContext(state, stream, "block"); | |
145 | } else if (type == "}" && state.context.prev) { | |
146 | return popContext(state); | |
147 | } else if (type == "@media") { | |
148 | return pushContext(state, stream, "media"); | |
149 | } else if (type == "@font-face") { | |
150 | return "font_face_before"; | |
151 | } else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) { | |
152 | return "keyframes"; | |
153 | } else if (type && type.charAt(0) == "@") { | |
154 | return pushContext(state, stream, "at"); | |
155 | } else if (type == "hash") { | |
156 | override = "builtin"; | |
157 | } else if (type == "word") { | |
158 | override = "tag"; | |
159 | } else if (type == "variable-definition") { | |
160 | return "maybeprop"; | |
161 | } else if (type == "interpolation") { | |
162 | return pushContext(state, stream, "interpolation"); | |
163 | } else if (type == ":") { | |
164 | return "pseudo"; | |
165 | } else if (allowNested && type == "(") { | |
166 | return pushContext(state, stream, "params"); | |
167 | } | |
168 | return state.context.type; | |
169 | }; | |
170 | ||
171 | states.block = function(type, stream, state) { | |
172 | if (type == "word") { | |
173 | if (propertyKeywords.hasOwnProperty(stream.current().toLowerCase())) { | |
174 | override = "property"; | |
175 | return "maybeprop"; | |
176 | } else if (allowNested) { | |
177 | override = stream.match(/^\s*:/, false) ? "property" : "tag"; | |
178 | return "block"; | |
179 | } else { | |
180 | override += " error"; | |
181 | return "maybeprop"; | |
182 | } | |
183 | } else if (type == "meta") { | |
184 | return "block"; | |
185 | } else if (!allowNested && (type == "hash" || type == "qualifier")) { | |
186 | override = "error"; | |
187 | return "block"; | |
188 | } else { | |
189 | return states.top(type, stream, state); | |
190 | } | |
191 | }; | |
192 | ||
193 | states.maybeprop = function(type, stream, state) { | |
194 | if (type == ":") return pushContext(state, stream, "prop"); | |
195 | return pass(type, stream, state); | |
196 | }; | |
197 | ||
198 | states.prop = function(type, stream, state) { | |
199 | if (type == ";") return popContext(state); | |
200 | if (type == "{" && allowNested) return pushContext(state, stream, "propBlock"); | |
201 | if (type == "}" || type == "{") return popAndPass(type, stream, state); | |
202 | if (type == "(") return pushContext(state, stream, "parens"); | |
203 | ||
204 | if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) { | |
205 | override += " error"; | |
206 | } else if (type == "word") { | |
207 | wordAsValue(stream); | |
208 | } else if (type == "interpolation") { | |
209 | return pushContext(state, stream, "interpolation"); | |
210 | } | |
211 | return "prop"; | |
212 | }; | |
213 | ||
214 | states.propBlock = function(type, _stream, state) { | |
215 | if (type == "}") return popContext(state); | |
216 | if (type == "word") { override = "property"; return "maybeprop"; } | |
217 | return state.context.type; | |
218 | }; | |
219 | ||
220 | states.parens = function(type, stream, state) { | |
221 | if (type == "{" || type == "}") return popAndPass(type, stream, state); | |
222 | if (type == ")") return popContext(state); | |
223 | return "parens"; | |
224 | }; | |
225 | ||
226 | states.pseudo = function(type, stream, state) { | |
227 | if (type == "word") { | |
228 | override = "variable-3"; | |
229 | return state.context.type; | |
230 | } | |
231 | return pass(type, stream, state); | |
232 | }; | |
233 | ||
234 | states.media = function(type, stream, state) { | |
235 | if (type == "(") return pushContext(state, stream, "media_parens"); | |
236 | if (type == "}") return popAndPass(type, stream, state); | |
237 | if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top"); | |
238 | ||
239 | if (type == "word") { | |
240 | var word = stream.current().toLowerCase(); | |
241 | if (word == "only" || word == "not" || word == "and") | |
242 | override = "keyword"; | |
243 | else if (mediaTypes.hasOwnProperty(word)) | |
244 | override = "attribute"; | |
245 | else if (mediaFeatures.hasOwnProperty(word)) | |
246 | override = "property"; | |
247 | else | |
248 | override = "error"; | |
249 | } | |
250 | return state.context.type; | |
251 | }; | |
252 | ||
253 | states.media_parens = function(type, stream, state) { | |
254 | if (type == ")") return popContext(state); | |
255 | if (type == "{" || type == "}") return popAndPass(type, stream, state, 2); | |
256 | return states.media(type, stream, state); | |
257 | }; | |
258 | ||
259 | states.font_face_before = function(type, stream, state) { | |
260 | if (type == "{") | |
261 | return pushContext(state, stream, "font_face"); | |
262 | return pass(type, stream, state); | |
263 | }; | |
264 | ||
265 | states.font_face = function(type, stream, state) { | |
266 | if (type == "}") return popContext(state); | |
267 | if (type == "word") { | |
268 | if (!fontProperties.hasOwnProperty(stream.current().toLowerCase())) | |
269 | override = "error"; | |
270 | else | |
271 | override = "property"; | |
272 | return "maybeprop"; | |
273 | } | |
274 | return "font_face"; | |
275 | }; | |
276 | ||
277 | states.keyframes = function(type, stream, state) { | |
278 | if (type == "word") { override = "variable"; return "keyframes"; } | |
279 | if (type == "{") return pushContext(state, stream, "top"); | |
280 | return pass(type, stream, state); | |
281 | }; | |
282 | ||
283 | states.at = function(type, stream, state) { | |
284 | if (type == ";") return popContext(state); | |
285 | if (type == "{" || type == "}") return popAndPass(type, stream, state); | |
286 | if (type == "word") override = "tag"; | |
287 | else if (type == "hash") override = "builtin"; | |
288 | return "at"; | |
289 | }; | |
290 | ||
291 | states.interpolation = function(type, stream, state) { | |
292 | if (type == "}") return popContext(state); | |
293 | if (type == "{" || type == ";") return popAndPass(type, stream, state); | |
294 | if (type != "variable") override = "error"; | |
295 | return "interpolation"; | |
296 | }; | |
297 | ||
298 | states.params = function(type, stream, state) { | |
299 | if (type == ")") return popContext(state); | |
300 | if (type == "{" || type == "}") return popAndPass(type, stream, state); | |
301 | if (type == "word") wordAsValue(stream); | |
302 | return "params"; | |
303 | }; | |
304 | ||
77b7b761 TD |
305 | return { |
306 | startState: function(base) { | |
837afb80 TD |
307 | return {tokenize: null, |
308 | state: "top", | |
309 | context: new Context("top", base || 0, null)}; | |
77b7b761 TD |
310 | }, |
311 | ||
312 | token: function(stream, state) { | |
837afb80 TD |
313 | if (!state.tokenize && stream.eatSpace()) return null; |
314 | var style = (state.tokenize || tokenBase)(stream, state); | |
315 | if (style && typeof style == "object") { | |
316 | type = style[1]; | |
317 | style = style[0]; | |
77b7b761 | 318 | } |
837afb80 TD |
319 | override = style; |
320 | state.state = states[state.state](type, stream, state); | |
321 | return override; | |
77b7b761 TD |
322 | }, |
323 | ||
324 | indent: function(state, textAfter) { | |
837afb80 TD |
325 | var cx = state.context, ch = textAfter && textAfter.charAt(0); |
326 | var indent = cx.indent; | |
327 | if (cx.type == "prop" && ch == "}") cx = cx.prev; | |
328 | if (cx.prev && | |
329 | (ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "font_face") || | |
330 | ch == ")" && (cx.type == "parens" || cx.type == "params" || cx.type == "media_parens") || | |
331 | ch == "{" && (cx.type == "at" || cx.type == "media"))) { | |
332 | indent = cx.indent - indentUnit; | |
333 | cx = cx.prev; | |
334 | } | |
335 | return indent; | |
77b7b761 TD |
336 | }, |
337 | ||
338 | electricChars: "}", | |
339 | blockCommentStart: "/*", | |
837afb80 TD |
340 | blockCommentEnd: "*/", |
341 | fold: "brace" | |
77b7b761 TD |
342 | }; |
343 | }); | |
344 | ||
77b7b761 TD |
345 | function keySet(array) { |
346 | var keys = {}; | |
347 | for (var i = 0; i < array.length; ++i) { | |
348 | keys[array[i]] = true; | |
349 | } | |
350 | return keys; | |
351 | } | |
352 | ||
837afb80 | 353 | var mediaTypes_ = [ |
77b7b761 TD |
354 | "all", "aural", "braille", "handheld", "print", "projection", "screen", |
355 | "tty", "tv", "embossed" | |
837afb80 | 356 | ], mediaTypes = keySet(mediaTypes_); |
77b7b761 | 357 | |
837afb80 | 358 | var mediaFeatures_ = [ |
77b7b761 TD |
359 | "width", "min-width", "max-width", "height", "min-height", "max-height", |
360 | "device-width", "min-device-width", "max-device-width", "device-height", | |
361 | "min-device-height", "max-device-height", "aspect-ratio", | |
362 | "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio", | |
363 | "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color", | |
364 | "max-color", "color-index", "min-color-index", "max-color-index", | |
365 | "monochrome", "min-monochrome", "max-monochrome", "resolution", | |
366 | "min-resolution", "max-resolution", "scan", "grid" | |
837afb80 | 367 | ], mediaFeatures = keySet(mediaFeatures_); |
77b7b761 | 368 | |
837afb80 | 369 | var propertyKeywords_ = [ |
77b7b761 TD |
370 | "align-content", "align-items", "align-self", "alignment-adjust", |
371 | "alignment-baseline", "anchor-point", "animation", "animation-delay", | |
837afb80 TD |
372 | "animation-direction", "animation-duration", "animation-fill-mode", |
373 | "animation-iteration-count", "animation-name", "animation-play-state", | |
374 | "animation-timing-function", "appearance", "azimuth", "backface-visibility", | |
375 | "background", "background-attachment", "background-clip", "background-color", | |
77b7b761 TD |
376 | "background-image", "background-origin", "background-position", |
377 | "background-repeat", "background-size", "baseline-shift", "binding", | |
378 | "bleed", "bookmark-label", "bookmark-level", "bookmark-state", | |
379 | "bookmark-target", "border", "border-bottom", "border-bottom-color", | |
380 | "border-bottom-left-radius", "border-bottom-right-radius", | |
381 | "border-bottom-style", "border-bottom-width", "border-collapse", | |
382 | "border-color", "border-image", "border-image-outset", | |
383 | "border-image-repeat", "border-image-slice", "border-image-source", | |
384 | "border-image-width", "border-left", "border-left-color", | |
385 | "border-left-style", "border-left-width", "border-radius", "border-right", | |
386 | "border-right-color", "border-right-style", "border-right-width", | |
387 | "border-spacing", "border-style", "border-top", "border-top-color", | |
388 | "border-top-left-radius", "border-top-right-radius", "border-top-style", | |
389 | "border-top-width", "border-width", "bottom", "box-decoration-break", | |
390 | "box-shadow", "box-sizing", "break-after", "break-before", "break-inside", | |
391 | "caption-side", "clear", "clip", "color", "color-profile", "column-count", | |
392 | "column-fill", "column-gap", "column-rule", "column-rule-color", | |
393 | "column-rule-style", "column-rule-width", "column-span", "column-width", | |
394 | "columns", "content", "counter-increment", "counter-reset", "crop", "cue", | |
395 | "cue-after", "cue-before", "cursor", "direction", "display", | |
396 | "dominant-baseline", "drop-initial-after-adjust", | |
397 | "drop-initial-after-align", "drop-initial-before-adjust", | |
398 | "drop-initial-before-align", "drop-initial-size", "drop-initial-value", | |
399 | "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis", | |
400 | "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", | |
837afb80 TD |
401 | "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings", |
402 | "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust", | |
77b7b761 TD |
403 | "font-stretch", "font-style", "font-synthesis", "font-variant", |
404 | "font-variant-alternates", "font-variant-caps", "font-variant-east-asian", | |
405 | "font-variant-ligatures", "font-variant-numeric", "font-variant-position", | |
837afb80 TD |
406 | "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow", |
407 | "grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end", | |
408 | "grid-column-start", "grid-row", "grid-row-end", "grid-row-start", | |
409 | "grid-template", "grid-template-areas", "grid-template-columns", | |
410 | "grid-template-rows", "hanging-punctuation", "height", "hyphens", | |
77b7b761 TD |
411 | "icon", "image-orientation", "image-rendering", "image-resolution", |
412 | "inline-box-align", "justify-content", "left", "letter-spacing", | |
413 | "line-break", "line-height", "line-stacking", "line-stacking-ruby", | |
414 | "line-stacking-shift", "line-stacking-strategy", "list-style", | |
415 | "list-style-image", "list-style-position", "list-style-type", "margin", | |
416 | "margin-bottom", "margin-left", "margin-right", "margin-top", | |
417 | "marker-offset", "marks", "marquee-direction", "marquee-loop", | |
418 | "marquee-play-count", "marquee-speed", "marquee-style", "max-height", | |
419 | "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index", | |
420 | "nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline", | |
421 | "outline-color", "outline-offset", "outline-style", "outline-width", | |
422 | "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y", | |
423 | "padding", "padding-bottom", "padding-left", "padding-right", "padding-top", | |
424 | "page", "page-break-after", "page-break-before", "page-break-inside", | |
425 | "page-policy", "pause", "pause-after", "pause-before", "perspective", | |
426 | "perspective-origin", "pitch", "pitch-range", "play-during", "position", | |
837afb80 TD |
427 | "presentation-level", "punctuation-trim", "quotes", "region-break-after", |
428 | "region-break-before", "region-break-inside", "region-fragment", | |
429 | "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness", | |
430 | "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang", | |
431 | "ruby-position", "ruby-span", "shape-inside", "shape-outside", "size", | |
432 | "speak", "speak-as", "speak-header", | |
77b7b761 TD |
433 | "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set", |
434 | "tab-size", "table-layout", "target", "target-name", "target-new", | |
435 | "target-position", "text-align", "text-align-last", "text-decoration", | |
436 | "text-decoration-color", "text-decoration-line", "text-decoration-skip", | |
437 | "text-decoration-style", "text-emphasis", "text-emphasis-color", | |
438 | "text-emphasis-position", "text-emphasis-style", "text-height", | |
837afb80 TD |
439 | "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow", |
440 | "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position", | |
77b7b761 TD |
441 | "text-wrap", "top", "transform", "transform-origin", "transform-style", |
442 | "transition", "transition-delay", "transition-duration", | |
443 | "transition-property", "transition-timing-function", "unicode-bidi", | |
444 | "vertical-align", "visibility", "voice-balance", "voice-duration", | |
445 | "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress", | |
446 | "voice-volume", "volume", "white-space", "widows", "width", "word-break", | |
837afb80 | 447 | "word-spacing", "word-wrap", "z-index", "zoom", |
77b7b761 TD |
448 | // SVG-specific |
449 | "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color", | |
450 | "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events", | |
451 | "color-interpolation", "color-interpolation-filters", "color-profile", | |
452 | "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering", | |
453 | "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke", | |
454 | "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", | |
455 | "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering", | |
456 | "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal", | |
457 | "glyph-orientation-vertical", "kerning", "text-anchor", "writing-mode" | |
837afb80 | 458 | ], propertyKeywords = keySet(propertyKeywords_); |
77b7b761 | 459 | |
837afb80 | 460 | var colorKeywords_ = [ |
77b7b761 TD |
461 | "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", |
462 | "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", | |
463 | "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", | |
464 | "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", | |
465 | "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", | |
466 | "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", | |
467 | "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", | |
468 | "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", | |
469 | "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", | |
837afb80 | 470 | "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", |
77b7b761 TD |
471 | "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", |
472 | "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", | |
473 | "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink", | |
474 | "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", | |
475 | "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", | |
476 | "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", | |
477 | "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", | |
478 | "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", | |
479 | "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", | |
480 | "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", | |
481 | "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", | |
482 | "purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", | |
483 | "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", | |
484 | "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", | |
485 | "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", | |
486 | "whitesmoke", "yellow", "yellowgreen" | |
837afb80 | 487 | ], colorKeywords = keySet(colorKeywords_); |
77b7b761 | 488 | |
837afb80 | 489 | var valueKeywords_ = [ |
77b7b761 TD |
490 | "above", "absolute", "activeborder", "activecaption", "afar", |
491 | "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate", | |
492 | "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", | |
837afb80 TD |
493 | "arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page", |
494 | "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary", | |
495 | "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box", | |
496 | "both", "bottom", "break", "break-all", "break-word", "button", "button-bevel", | |
77b7b761 TD |
497 | "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian", |
498 | "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", | |
499 | "cell", "center", "checkbox", "circle", "cjk-earthly-branch", | |
500 | "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote", | |
837afb80 | 501 | "col-resize", "collapse", "column", "compact", "condensed", "contain", "content", |
77b7b761 TD |
502 | "content-box", "context-menu", "continuous", "copy", "cover", "crop", |
503 | "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal", | |
504 | "decimal-leading-zero", "default", "default-button", "destination-atop", | |
505 | "destination-in", "destination-out", "destination-over", "devanagari", | |
506 | "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted", | |
507 | "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", | |
837afb80 | 508 | "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", |
77b7b761 TD |
509 | "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er", |
510 | "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", | |
511 | "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et", | |
512 | "ethiopic-halehame-gez", "ethiopic-halehame-om-et", | |
513 | "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et", | |
514 | "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", | |
515 | "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed", | |
516 | "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", | |
517 | "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove", | |
518 | "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", | |
519 | "help", "hidden", "hide", "higher", "highlight", "highlighttext", | |
520 | "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore", | |
521 | "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", | |
522 | "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", | |
523 | "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", | |
837afb80 | 524 | "italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer", |
77b7b761 TD |
525 | "landscape", "lao", "large", "larger", "left", "level", "lighter", |
526 | "line-through", "linear", "lines", "list-item", "listbox", "listitem", | |
527 | "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", | |
528 | "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian", | |
529 | "lower-roman", "lowercase", "ltr", "malayalam", "match", | |
530 | "media-controls-background", "media-current-time-display", | |
531 | "media-fullscreen-button", "media-mute-button", "media-play-button", | |
532 | "media-return-to-realtime-button", "media-rewind-button", | |
533 | "media-seek-back-button", "media-seek-forward-button", "media-slider", | |
534 | "media-sliderthumb", "media-time-remaining-display", "media-volume-slider", | |
535 | "media-volume-slider-container", "media-volume-sliderthumb", "medium", | |
536 | "menu", "menulist", "menulist-button", "menulist-text", | |
537 | "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", | |
538 | "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize", | |
539 | "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", | |
540 | "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", | |
541 | "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote", | |
542 | "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset", | |
837afb80 TD |
543 | "outside", "outside-shape", "overlay", "overline", "padding", "padding-box", |
544 | "painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer", | |
545 | "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button", | |
546 | "radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region", | |
547 | "relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba", | |
77b7b761 TD |
548 | "ridge", "right", "round", "row-resize", "rtl", "run-in", "running", |
549 | "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield", | |
550 | "searchfield-cancel-button", "searchfield-decoration", | |
551 | "searchfield-results-button", "searchfield-results-decoration", | |
552 | "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", | |
553 | "single", "skip-white-space", "slide", "slider-horizontal", | |
554 | "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", | |
555 | "small", "small-caps", "small-caption", "smaller", "solid", "somali", | |
556 | "source-atop", "source-in", "source-out", "source-over", "space", "square", | |
557 | "square-button", "start", "static", "status-bar", "stretch", "stroke", | |
558 | "sub", "subpixel-antialiased", "super", "sw-resize", "table", | |
559 | "table-caption", "table-cell", "table-column", "table-column-group", | |
560 | "table-footer-group", "table-header-group", "table-row", "table-row-group", | |
561 | "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", | |
562 | "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight", | |
563 | "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", | |
564 | "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top", | |
565 | "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", | |
566 | "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal", | |
567 | "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", | |
568 | "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted", | |
569 | "visibleStroke", "visual", "w-resize", "wait", "wave", "wider", | |
570 | "window", "windowframe", "windowtext", "x-large", "x-small", "xor", | |
571 | "xx-large", "xx-small" | |
837afb80 TD |
572 | ], valueKeywords = keySet(valueKeywords_); |
573 | ||
574 | var fontProperties_ = [ | |
575 | "font-family", "src", "unicode-range", "font-variant", "font-feature-settings", | |
576 | "font-stretch", "font-weight", "font-style" | |
577 | ], fontProperties = keySet(fontProperties_); | |
578 | ||
579 | var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_).concat(colorKeywords_).concat(valueKeywords_); | |
580 | CodeMirror.registerHelper("hintWords", "css", allWords); | |
77b7b761 TD |
581 | |
582 | function tokenCComment(stream, state) { | |
583 | var maybeEnd = false, ch; | |
584 | while ((ch = stream.next()) != null) { | |
585 | if (maybeEnd && ch == "/") { | |
586 | state.tokenize = null; | |
587 | break; | |
588 | } | |
589 | maybeEnd = (ch == "*"); | |
590 | } | |
591 | return ["comment", "comment"]; | |
592 | } | |
593 | ||
837afb80 TD |
594 | function tokenSGMLComment(stream, state) { |
595 | if (stream.skipTo("-->")) { | |
596 | stream.match("-->"); | |
597 | state.tokenize = null; | |
598 | } else { | |
599 | stream.skipToEnd(); | |
600 | } | |
601 | return ["comment", "comment"]; | |
602 | } | |
603 | ||
77b7b761 | 604 | CodeMirror.defineMIME("text/css", { |
837afb80 TD |
605 | mediaTypes: mediaTypes, |
606 | mediaFeatures: mediaFeatures, | |
77b7b761 TD |
607 | propertyKeywords: propertyKeywords, |
608 | colorKeywords: colorKeywords, | |
609 | valueKeywords: valueKeywords, | |
837afb80 TD |
610 | fontProperties: fontProperties, |
611 | tokenHooks: { | |
77b7b761 | 612 | "<": function(stream, state) { |
837afb80 TD |
613 | if (!stream.match("!--")) return false; |
614 | state.tokenize = tokenSGMLComment; | |
615 | return tokenSGMLComment(stream, state); | |
77b7b761 TD |
616 | }, |
617 | "/": function(stream, state) { | |
837afb80 TD |
618 | if (!stream.eat("*")) return false; |
619 | state.tokenize = tokenCComment; | |
620 | return tokenCComment(stream, state); | |
77b7b761 TD |
621 | } |
622 | }, | |
837afb80 | 623 | name: "css" |
77b7b761 TD |
624 | }); |
625 | ||
626 | CodeMirror.defineMIME("text/x-scss", { | |
837afb80 TD |
627 | mediaTypes: mediaTypes, |
628 | mediaFeatures: mediaFeatures, | |
77b7b761 TD |
629 | propertyKeywords: propertyKeywords, |
630 | colorKeywords: colorKeywords, | |
631 | valueKeywords: valueKeywords, | |
837afb80 | 632 | fontProperties: fontProperties, |
77b7b761 | 633 | allowNested: true, |
837afb80 | 634 | tokenHooks: { |
77b7b761 TD |
635 | "/": function(stream, state) { |
636 | if (stream.eat("/")) { | |
637 | stream.skipToEnd(); | |
638 | return ["comment", "comment"]; | |
639 | } else if (stream.eat("*")) { | |
640 | state.tokenize = tokenCComment; | |
641 | return tokenCComment(stream, state); | |
642 | } else { | |
643 | return ["operator", "operator"]; | |
644 | } | |
645 | }, | |
837afb80 TD |
646 | ":": function(stream) { |
647 | if (stream.match(/\s*{/)) | |
648 | return [null, "{"]; | |
649 | return false; | |
650 | }, | |
651 | "$": function(stream) { | |
652 | stream.match(/^[\w-]+/); | |
653 | if (stream.match(/^\s*:/, false)) | |
654 | return ["variable-2", "variable-definition"]; | |
655 | return ["variable-2", "variable"]; | |
656 | }, | |
77b7b761 | 657 | "#": function(stream) { |
837afb80 TD |
658 | if (!stream.eat("{")) return false; |
659 | return [null, "interpolation"]; | |
660 | } | |
661 | }, | |
662 | name: "css", | |
663 | helperType: "scss" | |
664 | }); | |
665 | ||
666 | CodeMirror.defineMIME("text/x-less", { | |
667 | mediaTypes: mediaTypes, | |
668 | mediaFeatures: mediaFeatures, | |
669 | propertyKeywords: propertyKeywords, | |
670 | colorKeywords: colorKeywords, | |
671 | valueKeywords: valueKeywords, | |
672 | fontProperties: fontProperties, | |
673 | allowNested: true, | |
674 | tokenHooks: { | |
675 | "/": function(stream, state) { | |
676 | if (stream.eat("/")) { | |
677 | stream.skipToEnd(); | |
678 | return ["comment", "comment"]; | |
679 | } else if (stream.eat("*")) { | |
680 | state.tokenize = tokenCComment; | |
681 | return tokenCComment(stream, state); | |
77b7b761 | 682 | } else { |
837afb80 | 683 | return ["operator", "operator"]; |
77b7b761 | 684 | } |
837afb80 TD |
685 | }, |
686 | "@": function(stream) { | |
687 | if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false; | |
688 | stream.eatWhile(/[\w\\\-]/); | |
689 | if (stream.match(/^\s*:/, false)) | |
690 | return ["variable-2", "variable-definition"]; | |
691 | return ["variable-2", "variable"]; | |
692 | }, | |
693 | "&": function() { | |
694 | return ["atom", "atom"]; | |
77b7b761 TD |
695 | } |
696 | }, | |
837afb80 TD |
697 | name: "css", |
698 | helperType: "less" | |
77b7b761 | 699 | }); |
837afb80 TD |
700 | |
701 | }); |