browser/devtools/sourceeditor/codemirror/css.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial