Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make CSS mode configurable, use it to implement SCSS mode.

  • Loading branch information...
commit 1171acb083d681a6d657c67058341c3e9b483ae7 1 parent 9565019
@dqminh dqminh authored marijnh committed
View
575 mode/css/css.js
@@ -1,204 +1,25 @@
-CodeMirror.defineMode("css", function(config) {
- var indentUnit = config.indentUnit, type;
-
- var atMediaTypes = keySet([
- "all", "aural", "braille", "handheld", "print", "projection", "screen",
- "tty", "tv", "embossed"
- ]);
-
- var atMediaFeatures = keySet([
- "width", "min-width", "max-width", "height", "min-height", "max-height",
- "device-width", "min-device-width", "max-device-width", "device-height",
- "min-device-height", "max-device-height", "aspect-ratio",
- "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
- "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
- "max-color", "color-index", "min-color-index", "max-color-index",
- "monochrome", "min-monochrome", "max-monochrome", "resolution",
- "min-resolution", "max-resolution", "scan", "grid"
- ]);
-
- var propertyKeywords = keySet([
- "align-content", "align-items", "align-self", "alignment-adjust",
- "alignment-baseline", "anchor-point", "animation", "animation-delay",
- "animation-direction", "animation-duration", "animation-iteration-count",
- "animation-name", "animation-play-state", "animation-timing-function",
- "appearance", "azimuth", "backface-visibility", "background",
- "background-attachment", "background-clip", "background-color",
- "background-image", "background-origin", "background-position",
- "background-repeat", "background-size", "baseline-shift", "binding",
- "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
- "bookmark-target", "border", "border-bottom", "border-bottom-color",
- "border-bottom-left-radius", "border-bottom-right-radius",
- "border-bottom-style", "border-bottom-width", "border-collapse",
- "border-color", "border-image", "border-image-outset",
- "border-image-repeat", "border-image-slice", "border-image-source",
- "border-image-width", "border-left", "border-left-color",
- "border-left-style", "border-left-width", "border-radius", "border-right",
- "border-right-color", "border-right-style", "border-right-width",
- "border-spacing", "border-style", "border-top", "border-top-color",
- "border-top-left-radius", "border-top-right-radius", "border-top-style",
- "border-top-width", "border-width", "bottom", "box-decoration-break",
- "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
- "caption-side", "clear", "clip", "color", "color-profile", "column-count",
- "column-fill", "column-gap", "column-rule", "column-rule-color",
- "column-rule-style", "column-rule-width", "column-span", "column-width",
- "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
- "cue-after", "cue-before", "cursor", "direction", "display",
- "dominant-baseline", "drop-initial-after-adjust",
- "drop-initial-after-align", "drop-initial-before-adjust",
- "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
- "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
- "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
- "float", "float-offset", "font", "font-feature-settings", "font-family",
- "font-kerning", "font-language-override", "font-size", "font-size-adjust",
- "font-stretch", "font-style", "font-synthesis", "font-variant",
- "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
- "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
- "font-weight", "grid-cell", "grid-column", "grid-column-align",
- "grid-column-sizing", "grid-column-span", "grid-columns", "grid-flow",
- "grid-row", "grid-row-align", "grid-row-sizing", "grid-row-span",
- "grid-rows", "grid-template", "hanging-punctuation", "height", "hyphens",
- "icon", "image-orientation", "image-rendering", "image-resolution",
- "inline-box-align", "justify-content", "left", "letter-spacing",
- "line-break", "line-height", "line-stacking", "line-stacking-ruby",
- "line-stacking-shift", "line-stacking-strategy", "list-style",
- "list-style-image", "list-style-position", "list-style-type", "margin",
- "margin-bottom", "margin-left", "margin-right", "margin-top",
- "marker-offset", "marks", "marquee-direction", "marquee-loop",
- "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
- "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
- "nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline",
- "outline-color", "outline-offset", "outline-style", "outline-width",
- "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
- "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
- "page", "page-break-after", "page-break-before", "page-break-inside",
- "page-policy", "pause", "pause-after", "pause-before", "perspective",
- "perspective-origin", "pitch", "pitch-range", "play-during", "position",
- "presentation-level", "punctuation-trim", "quotes", "rendering-intent",
- "resize", "rest", "rest-after", "rest-before", "richness", "right",
- "rotation", "rotation-point", "ruby-align", "ruby-overhang",
- "ruby-position", "ruby-span", "size", "speak", "speak-as", "speak-header",
- "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
- "tab-size", "table-layout", "target", "target-name", "target-new",
- "target-position", "text-align", "text-align-last", "text-decoration",
- "text-decoration-color", "text-decoration-line", "text-decoration-skip",
- "text-decoration-style", "text-emphasis", "text-emphasis-color",
- "text-emphasis-position", "text-emphasis-style", "text-height",
- "text-indent", "text-justify", "text-outline", "text-shadow",
- "text-space-collapse", "text-transform", "text-underline-position",
- "text-wrap", "top", "transform", "transform-origin", "transform-style",
- "transition", "transition-delay", "transition-duration",
- "transition-property", "transition-timing-function", "unicode-bidi",
- "vertical-align", "visibility", "voice-balance", "voice-duration",
- "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
- "voice-volume", "volume", "white-space", "widows", "width", "word-break",
- "word-spacing", "word-wrap", "z-index"
- ]);
-
- var colorKeywords = keySet([
- "black", "silver", "gray", "white", "maroon", "red", "purple", "fuchsia",
- "green", "lime", "olive", "yellow", "navy", "blue", "teal", "aqua"
- ]);
-
- var valueKeywords = keySet([
- "above", "absolute", "activeborder", "activecaption", "afar",
- "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
- "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
- "arabic-indic", "armenian", "asterisks", "auto", "avoid", "background",
- "backwards", "baseline", "below", "bidi-override", "binary", "bengali",
- "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
- "both", "bottom", "break-all", "break-word", "button", "button-bevel",
- "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
- "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
- "cell", "center", "checkbox", "circle", "cjk-earthly-branch",
- "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
- "col-resize", "collapse", "compact", "condensed", "contain", "content",
- "content-box", "context-menu", "continuous", "copy", "cover", "crop",
- "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
- "decimal-leading-zero", "default", "default-button", "destination-atop",
- "destination-in", "destination-out", "destination-over", "devanagari",
- "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
- "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
- "element", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
- "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
- "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
- "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
- "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
- "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
- "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
- "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
- "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
- "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
- "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
- "help", "hidden", "hide", "higher", "highlight", "highlighttext",
- "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
- "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
- "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
- "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
- "italic", "justify", "kannada", "katakana", "katakana-iroha", "khmer",
- "landscape", "lao", "large", "larger", "left", "level", "lighter",
- "line-through", "linear", "lines", "list-item", "listbox", "listitem",
- "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
- "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
- "lower-roman", "lowercase", "ltr", "malayalam", "match",
- "media-controls-background", "media-current-time-display",
- "media-fullscreen-button", "media-mute-button", "media-play-button",
- "media-return-to-realtime-button", "media-rewind-button",
- "media-seek-back-button", "media-seek-forward-button", "media-slider",
- "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
- "media-volume-slider-container", "media-volume-sliderthumb", "medium",
- "menu", "menulist", "menulist-button", "menulist-text",
- "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
- "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
- "narrower", "navy", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
- "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
- "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
- "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
- "outside", "overlay", "overline", "padding", "padding-box", "painted",
- "paused", "persian", "plus-darker", "plus-lighter", "pointer", "portrait",
- "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
- "radio", "read-only", "read-write", "read-write-plaintext-only", "relative",
- "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
- "ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
- "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
- "searchfield-cancel-button", "searchfield-decoration",
- "searchfield-results-button", "searchfield-results-decoration",
- "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
- "single", "skip-white-space", "slide", "slider-horizontal",
- "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
- "small", "small-caps", "small-caption", "smaller", "solid", "somali",
- "source-atop", "source-in", "source-out", "source-over", "space", "square",
- "square-button", "start", "static", "status-bar", "stretch", "stroke",
- "sub", "subpixel-antialiased", "super", "sw-resize", "table",
- "table-caption", "table-cell", "table-column", "table-column-group",
- "table-footer-group", "table-header-group", "table-row", "table-row-group",
- "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
- "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
- "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
- "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
- "transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
- "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
- "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
- "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
- "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider",
- "window", "windowframe", "windowtext", "x-large", "x-small", "xor",
- "xx-large", "xx-small", "yellow"
- ]);
+CodeMirror.defineMode("css", function(config, parserConfig) {
+ "use strict";
+ var indentUnit = config.indentUnit,
+ hooks = parserConfig.hooks || {},
+ atMediaTypes = parserConfig.atMediaTypes || {},
+ atMediaFeatures = parserConfig.atMediaFeatures || {},
+ propertyKeywords = parserConfig.propertyKeywords || {},
+ colorKeywords = parserConfig.colorKeywords || {},
+ valueKeywords = parserConfig.valueKeywords || {},
+ allowNested = !!parserConfig.allowNested,
+ type = null;
- function keySet(array) { var keys = {}; for (var i = 0; i < array.length; ++i) keys[array[i]] = true; return keys; }
- function ret(style, tp) {type = tp; return style;}
+ function ret(style, tp) { type = tp; return style; }
function tokenBase(stream, state) {
var ch = stream.next();
- if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("def", stream.current());}
- else if (ch == "/" && stream.eat("*")) {
- state.tokenize = tokenCComment;
- return tokenCComment(stream, state);
- }
- else if (ch == "<" && stream.eat("!")) {
- state.tokenize = tokenSGMLComment;
- return tokenSGMLComment(stream, state);
+ if (hooks[ch]) {
+ // result[0] is style and result[1] is type
+ var result = hooks[ch](stream, state);
+ if (result !== false) return ret(result[0], result[1]);
}
+ if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("def", stream.current());}
else if (ch == "=") ret(null, "compare");
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
else if (ch == "\"" || ch == "'") {
@@ -248,30 +69,6 @@ CodeMirror.defineMode("css", function(config) {
}
}
- function tokenCComment(stream, state) {
- var maybeEnd = false, ch;
- while ((ch = stream.next()) != null) {
- if (maybeEnd && ch == "/") {
- state.tokenize = tokenBase;
- break;
- }
- maybeEnd = (ch == "*");
- }
- return ret("comment", "comment");
- }
-
- function tokenSGMLComment(stream, state) {
- var dashes = 0, ch;
- while ((ch = stream.next()) != null) {
- if (dashes >= 2 && ch == ">") {
- state.tokenize = tokenBase;
- break;
- }
- dashes = (ch == "-") ? dashes + 1 : 0;
- }
- return ret("comment", "comment");
- }
-
function tokenString(quote, nonInclusive) {
return function(stream, state) {
var escaped = false, ch;
@@ -305,59 +102,63 @@ CodeMirror.defineMode("css", function(config) {
},
token: function(stream, state) {
-
+
// Use these terms when applicable (see http://www.xanthir.com/blog/b4E50)
- //
+ //
// rule** or **ruleset:
// A selector + braces combo, or an at-rule.
- //
+ //
// declaration block:
// A sequence of declarations.
- //
+ //
// declaration:
// A property + colon + value combo.
- //
+ //
// property value:
// The entire value of a property.
- //
+ //
// component value:
// A single piece of a property value. Like the 5px in
// text-shadow: 0 0 5px blue;. Can also refer to things that are
// multiple terms, like the 1-4 terms that make up the background-size
// portion of the background shorthand.
- //
+ //
// term:
// The basic unit of author-facing CSS, like a single number (5),
// dimension (5px), string ("foo"), or function. Officially defined
// by the CSS 2.1 grammar (look for the 'term' production)
- //
- //
+ //
+ //
// simple selector:
// A single atomic selector, like a type selector, an attr selector, a
// class selector, etc.
- //
+ //
// compound selector:
// One or more simple selectors without a combinator. div.example is
// compound, div > .example is not.
- //
+ //
// complex selector:
// One or more compound selectors chained with combinators.
- //
+ //
// combinator:
// The parts of selectors that express relationships. There are four
// currently - the space (descendant combinator), the greater-than
// bracket (child combinator), the plus sign (next sibling combinator),
// and the tilda (following sibling combinator).
- //
+ //
// sequence of selectors:
// One or more of the named type of selector chained with commas.
+ state.tokenize = state.tokenize || tokenBase;
if (state.tokenize == tokenBase && stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
// Changing style returned based on context
var context = state.stack[state.stack.length-1];
- if (style == "property") {
+ if (style == "variable") {
+ if (type == "variable-definition") state.stack.push("propertyValue");
+ return "variable-2";
+ } else if (style == "property") {
if (context == "propertyValue"){
if (valueKeywords[stream.current()]) {
style = "string-2";
@@ -370,6 +171,18 @@ CodeMirror.defineMode("css", function(config) {
if (!propertyKeywords[stream.current()]) {
style += " error";
}
+ } else if (context == "block") {
+ // if a value is present in both property, value, or color, the order
+ // of preference is property -> color -> value
+ if (propertyKeywords[stream.current()]) {
+ style = "property";
+ } else if (colorKeywords[stream.current()]) {
+ style = "keyword";
+ } else if (valueKeywords[stream.current()]) {
+ style = "string-2";
+ } else {
+ style = "tag";
+ }
} else if (!context || context == "@media{") {
style = "tag";
} else if (context == "@media") {
@@ -434,19 +247,25 @@ CodeMirror.defineMode("css", function(config) {
state.stack.pop();
state.stack[state.stack.length-1] = "@media{";
}
- else state.stack.push("rule");
+ else {
+ var newContext = allowNested ? "block" : "rule";
+ state.stack.push(newContext);
+ }
}
else if (type == "}") {
+ var lastState = state.stack[state.stack.length - 1];
+ if (lastState == "interpolation") style = "operator";
state.stack.pop();
if (context == "propertyValue") state.stack.pop();
}
+ else if (type == "interpolation") state.stack.push("interpolation");
else if (type == "@media") state.stack.push("@media");
else if (context == "@media" && /\b(keyword|attribute)\b/.test(style))
state.stack.push("@mediaType");
else if (context == "@mediaType" && stream.current() == ",") state.stack.pop();
else if (context == "@mediaType" && type == "(") state.stack.push("@mediaType(");
else if (context == "@mediaType(" && type == ")") state.stack.pop();
- else if (context == "rule" && type == ":") state.stack.push("propertyValue");
+ else if ((context == "rule" || context == "block") && type == ":") state.stack.push("propertyValue");
else if (context == "propertyValue" && type == ";") state.stack.pop();
return style;
},
@@ -462,4 +281,286 @@ CodeMirror.defineMode("css", function(config) {
};
});
-CodeMirror.defineMIME("text/css", "css");
+(function() {
+ function mimes(ms, mode) {
+ for (var i = 0; i < ms.length; ++i) {
+ CodeMirror.defineMIME(ms[i], mode);
+ }
+ }
+
+ function keySet(array) {
+ var keys = {};
+ for (var i = 0; i < array.length; ++i) {
+ keys[array[i]] = true;
+ }
+ return keys;
+ }
+
+ var atMediaTypes = [
+ "all", "aural", "braille", "handheld", "print", "projection", "screen",
+ "tty", "tv", "embossed"
+ ];
+
+ var atMediaFeatures = [
+ "width", "min-width", "max-width", "height", "min-height", "max-height",
+ "device-width", "min-device-width", "max-device-width", "device-height",
+ "min-device-height", "max-device-height", "aspect-ratio",
+ "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
+ "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
+ "max-color", "color-index", "min-color-index", "max-color-index",
+ "monochrome", "min-monochrome", "max-monochrome", "resolution",
+ "min-resolution", "max-resolution", "scan", "grid"
+ ];
+
+ var propertyKeywords = [
+ "align-content", "align-items", "align-self", "alignment-adjust",
+ "alignment-baseline", "anchor-point", "animation", "animation-delay",
+ "animation-direction", "animation-duration", "animation-iteration-count",
+ "animation-name", "animation-play-state", "animation-timing-function",
+ "appearance", "azimuth", "backface-visibility", "background",
+ "background-attachment", "background-clip", "background-color",
+ "background-image", "background-origin", "background-position",
+ "background-repeat", "background-size", "baseline-shift", "binding",
+ "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
+ "bookmark-target", "border", "border-bottom", "border-bottom-color",
+ "border-bottom-left-radius", "border-bottom-right-radius",
+ "border-bottom-style", "border-bottom-width", "border-collapse",
+ "border-color", "border-image", "border-image-outset",
+ "border-image-repeat", "border-image-slice", "border-image-source",
+ "border-image-width", "border-left", "border-left-color",
+ "border-left-style", "border-left-width", "border-radius", "border-right",
+ "border-right-color", "border-right-style", "border-right-width",
+ "border-spacing", "border-style", "border-top", "border-top-color",
+ "border-top-left-radius", "border-top-right-radius", "border-top-style",
+ "border-top-width", "border-width", "bottom", "box-decoration-break",
+ "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
+ "caption-side", "clear", "clip", "color", "color-profile", "column-count",
+ "column-fill", "column-gap", "column-rule", "column-rule-color",
+ "column-rule-style", "column-rule-width", "column-span", "column-width",
+ "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
+ "cue-after", "cue-before", "cursor", "direction", "display",
+ "dominant-baseline", "drop-initial-after-adjust",
+ "drop-initial-after-align", "drop-initial-before-adjust",
+ "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
+ "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
+ "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
+ "float", "float-offset", "font", "font-feature-settings", "font-family",
+ "font-kerning", "font-language-override", "font-size", "font-size-adjust",
+ "font-stretch", "font-style", "font-synthesis", "font-variant",
+ "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
+ "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
+ "font-weight", "grid-cell", "grid-column", "grid-column-align",
+ "grid-column-sizing", "grid-column-span", "grid-columns", "grid-flow",
+ "grid-row", "grid-row-align", "grid-row-sizing", "grid-row-span",
+ "grid-rows", "grid-template", "hanging-punctuation", "height", "hyphens",
+ "icon", "image-orientation", "image-rendering", "image-resolution",
+ "inline-box-align", "justify-content", "left", "letter-spacing",
+ "line-break", "line-height", "line-stacking", "line-stacking-ruby",
+ "line-stacking-shift", "line-stacking-strategy", "list-style",
+ "list-style-image", "list-style-position", "list-style-type", "margin",
+ "margin-bottom", "margin-left", "margin-right", "margin-top",
+ "marker-offset", "marks", "marquee-direction", "marquee-loop",
+ "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
+ "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
+ "nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline",
+ "outline-color", "outline-offset", "outline-style", "outline-width",
+ "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
+ "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
+ "page", "page-break-after", "page-break-before", "page-break-inside",
+ "page-policy", "pause", "pause-after", "pause-before", "perspective",
+ "perspective-origin", "pitch", "pitch-range", "play-during", "position",
+ "presentation-level", "punctuation-trim", "quotes", "rendering-intent",
+ "resize", "rest", "rest-after", "rest-before", "richness", "right",
+ "rotation", "rotation-point", "ruby-align", "ruby-overhang",
+ "ruby-position", "ruby-span", "size", "speak", "speak-as", "speak-header",
+ "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
+ "tab-size", "table-layout", "target", "target-name", "target-new",
+ "target-position", "text-align", "text-align-last", "text-decoration",
+ "text-decoration-color", "text-decoration-line", "text-decoration-skip",
+ "text-decoration-style", "text-emphasis", "text-emphasis-color",
+ "text-emphasis-position", "text-emphasis-style", "text-height",
+ "text-indent", "text-justify", "text-outline", "text-shadow",
+ "text-space-collapse", "text-transform", "text-underline-position",
+ "text-wrap", "top", "transform", "transform-origin", "transform-style",
+ "transition", "transition-delay", "transition-duration",
+ "transition-property", "transition-timing-function", "unicode-bidi",
+ "vertical-align", "visibility", "voice-balance", "voice-duration",
+ "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
+ "voice-volume", "volume", "white-space", "widows", "width", "word-break",
+ "word-spacing", "word-wrap", "z-index"
+ ];
+
+ var colorKeywords = [
+ "black", "silver", "gray", "white", "maroon", "red", "purple", "fuchsia",
+ "green", "lime", "olive", "yellow", "navy", "blue", "teal", "aqua"
+ ];
+
+ var valueKeywords = [
+ "above", "absolute", "activeborder", "activecaption", "afar",
+ "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
+ "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
+ "arabic-indic", "armenian", "asterisks", "auto", "avoid", "background",
+ "backwards", "baseline", "below", "bidi-override", "binary", "bengali",
+ "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
+ "both", "bottom", "break-all", "break-word", "button", "button-bevel",
+ "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
+ "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
+ "cell", "center", "checkbox", "circle", "cjk-earthly-branch",
+ "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
+ "col-resize", "collapse", "compact", "condensed", "contain", "content",
+ "content-box", "context-menu", "continuous", "copy", "cover", "crop",
+ "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
+ "decimal-leading-zero", "default", "default-button", "destination-atop",
+ "destination-in", "destination-out", "destination-over", "devanagari",
+ "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
+ "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
+ "element", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
+ "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
+ "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
+ "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
+ "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
+ "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
+ "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
+ "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
+ "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
+ "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
+ "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
+ "help", "hidden", "hide", "higher", "highlight", "highlighttext",
+ "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
+ "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
+ "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
+ "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
+ "italic", "justify", "kannada", "katakana", "katakana-iroha", "khmer",
+ "landscape", "lao", "large", "larger", "left", "level", "lighter",
+ "line-through", "linear", "lines", "list-item", "listbox", "listitem",
+ "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
+ "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
+ "lower-roman", "lowercase", "ltr", "malayalam", "match",
+ "media-controls-background", "media-current-time-display",
+ "media-fullscreen-button", "media-mute-button", "media-play-button",
+ "media-return-to-realtime-button", "media-rewind-button",
+ "media-seek-back-button", "media-seek-forward-button", "media-slider",
+ "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
+ "media-volume-slider-container", "media-volume-sliderthumb", "medium",
+ "menu", "menulist", "menulist-button", "menulist-text",
+ "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
+ "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
+ "narrower", "navy", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
+ "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
+ "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
+ "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
+ "outside", "overlay", "overline", "padding", "padding-box", "painted",
+ "paused", "persian", "plus-darker", "plus-lighter", "pointer", "portrait",
+ "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
+ "radio", "read-only", "read-write", "read-write-plaintext-only", "relative",
+ "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
+ "ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
+ "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
+ "searchfield-cancel-button", "searchfield-decoration",
+ "searchfield-results-button", "searchfield-results-decoration",
+ "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
+ "single", "skip-white-space", "slide", "slider-horizontal",
+ "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
+ "small", "small-caps", "small-caption", "smaller", "solid", "somali",
+ "source-atop", "source-in", "source-out", "source-over", "space", "square",
+ "square-button", "start", "static", "status-bar", "stretch", "stroke",
+ "sub", "subpixel-antialiased", "super", "sw-resize", "table",
+ "table-caption", "table-cell", "table-column", "table-column-group",
+ "table-footer-group", "table-header-group", "table-row", "table-row-group",
+ "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
+ "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
+ "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
+ "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
+ "transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
+ "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
+ "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
+ "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
+ "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider",
+ "window", "windowframe", "windowtext", "x-large", "x-small", "xor",
+ "xx-large", "xx-small", "yellow"
+ ];
+
+ function tokenCComment(stream, state) {
+ var maybeEnd = false, ch;
+ while ((ch = stream.next()) != null) {
+ if (maybeEnd && ch == "/") {
+ state.tokenize = null;
+ break;
+ }
+ maybeEnd = (ch == "*");
+ }
+ return ["comment", "comment"];
+ }
+
+ mimes(['text/css', 'css'], {
+ atMediaTypes: keySet(atMediaTypes),
+ atMediaFeatures: keySet(atMediaFeatures),
+ propertyKeywords: keySet(propertyKeywords),
+ colorKeywords: keySet(colorKeywords),
+ valueKeywords: keySet(valueKeywords),
+ hooks: {
+ "<": function(stream, state) {
+ function tokenSGMLComment(stream, state) {
+ var dashes = 0, ch;
+ while ((ch = stream.next()) != null) {
+ if (dashes >= 2 && ch == ">") {
+ state.tokenize = null;
+ break;
+ }
+ dashes = (ch == "-") ? dashes + 1 : 0;
+ }
+ return ["comment", "comment"];
+ }
+ if (stream.eat("!")) {
+ state.tokenize = tokenSGMLComment;
+ return tokenSGMLComment(stream, state);
+ }
+ },
+ '/': function(stream, state) {
+ if (stream.eat("*")) {
+ state.tokenize = tokenCComment;
+ return tokenCComment(stream, state);
+ }
+ }
+ },
+ name: "css"
+ });
+
+ mimes(['text/x-scss', 'scss'], {
+ atMediaTypes: keySet(atMediaTypes),
+ atMediaFeatures: keySet(atMediaFeatures),
+ propertyKeywords: keySet(propertyKeywords),
+ colorKeywords: keySet(colorKeywords),
+ valueKeywords: keySet(valueKeywords),
+ allowNested: true,
+ hooks: {
+ "$": function(stream) {
+ stream.match(/^[\w-]+/);
+ if (stream.peek() == ':') {
+ return ["variable", "variable-definition"];
+ }
+ return ["variable", "variable"];
+ },
+ '/': function(stream, state) {
+ if (stream.eat('/')) {
+ stream.skipToEnd();
+ return ['comment', 'comment'];
+ } else if (stream.eat('*')) {
+ state.tokenize = tokenCComment;
+ return tokenCComment(stream, state);
+ } else {
+ return ["operator", "operator"];
+ }
+ },
+ '#': function(stream) {
+ if (stream.eat('{')) {
+ return ["operator", "interpolation"];
+ } else {
+ stream.eatWhile(/[\w\\\-]/);
+ return ["atom", "hash"];
+ }
+ }
+ },
+ name: "css"
+ });
+})();
View
142 mode/css/scss.html
@@ -0,0 +1,142 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>CodeMirror: SCSS mode</title>
+ <link rel="stylesheet" href="../../lib/codemirror.css">
+ <script src="../../lib/codemirror.js"></script>
+ <script src="css.js"></script>
+ <style>.CodeMirror {background: #f8f8f8;}</style>
+ <link rel="stylesheet" href="../../doc/docs.css">
+ </head>
+ <body>
+ <h1>CodeMirror: SCSS mode</h1>
+ <form><textarea id="code" name="code">
+/* Some example SCSS */
+
+@import "compass/css3";
+$variable: #333;
+
+$blue: #3bbfce;
+$margin: 16px;
+
+.content-navigation {
+ border-color: $blue;
+ color:
+ darken($blue, 9%);
+}
+
+.border {
+ padding: $margin / 2;
+ margin: $margin / 2;
+ border-color: $blue;
+}
+
+@mixin table-base {
+ th {
+ text-align: center;
+ font-weight: bold;
+ }
+ td, th {padding: 2px}
+}
+
+table.hl {
+ margin: 2em 0;
+ td.ln {
+ text-align: right;
+ }
+}
+
+li {
+ font: {
+ family: serif;
+ weight: bold;
+ size: 1.2em;
+ }
+}
+
+@mixin left($dist) {
+ float: left;
+ margin-left: $dist;
+}
+
+#data {
+ @include left(10px);
+ @include table-base;
+}
+
+.source {
+ @include flow-into(target);
+ border: 10px solid green;
+ margin: 20px;
+ width: 200px; }
+
+.new-container {
+ @include flow-from(target);
+ border: 10px solid red;
+ margin: 20px;
+ width: 200px; }
+
+body {
+ margin: 0;
+ padding: 3em 6em;
+ font-family: tahoma, arial, sans-serif;
+ color: #000;
+}
+
+@mixin yellow() {
+ background: yellow;
+}
+
+.big {
+ font-size: 14px;
+}
+
+.nested {
+ @include border-radius(3px);
+ @extend .big;
+ p {
+ background: whitesmoke;
+ a {
+ color: red;
+ }
+ }
+}
+
+#navigation a {
+ font-weight: bold;
+ text-decoration: none !important;
+}
+
+h1 {
+ font-size: 2.5em;
+}
+
+h2 {
+ font-size: 1.7em;
+}
+
+h1:before, h2:before {
+ content: "::";
+}
+
+code {
+ font-family: courier, monospace;
+ font-size: 80%;
+ color: #418A8A;
+}
+</textarea></form>
+ <script>
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
+ lineNumbers: true,
+ matchBrackets: true,
+ mode: "text/x-scss"
+ });
+ </script>
+
+ <p><strong>MIME types defined:</strong> <code>text/scss</code>.</p>
+
+ <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#scss_*">normal</a>, <a href="../../test/index.html#verbose,scss_*">verbose</a>.</p>
+
+ </body>
+</html>
View
77 mode/css/scss_test.js
@@ -0,0 +1,77 @@
+(function() {
+ var mode = CodeMirror.getMode({tabSize: 4}, "text/x-scss");
+ function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
+
+ MT('url_with_quotation',
+ "[tag foo] { [property background][operator :][string-2 url]([string test.jpg]) }");
+
+ MT('url_with_double_quotes',
+ "[tag foo] { [property background][operator :][string-2 url]([string \"test.jpg\"]) }");
+
+ MT('url_with_single_quotes',
+ "[tag foo] { [property background][operator :][string-2 url]([string \'test.jpg\']) }");
+
+ MT('string',
+ "[def @import] [string \"compass/css3\"]");
+
+ MT('important_keyword',
+ "[tag foo] { [property background][operator :][string-2 url]([string \'test.jpg\']) [keyword !important] }");
+
+ MT('variable',
+ "[variable-2 $blue][operator :][atom #333]");
+
+ MT('variable_as_attribute',
+ "[tag foo] { [property color][operator :][variable-2 $blue] }");
+
+ MT('numbers',
+ "[tag foo] { [property padding][operator :][number 10px] [number 10] [number 10em] [number 8in] }");
+
+ MT('number_percentage',
+ "[tag foo] { [property width][operator :][number 80%] }");
+
+ MT('selector',
+ "[builtin #hello][qualifier .world]{}");
+
+ MT('singleline_comment',
+ "[comment // this is a comment]");
+
+ MT('multiline_comment',
+ "[comment /*foobar*/]");
+
+ MT('attribute_with_hyphen',
+ "[tag foo] { [property font-size][operator :][number 10px] }");
+
+ MT('string_after_attribute',
+ "[tag foo] { [property content][operator :][string \"::\"] }");
+
+ MT('directives',
+ "[def @include] [qualifier .mixin]");
+
+ MT('basic_structure',
+ "[tag p] { [property background][operator :][keyword red]; }");
+
+ MT('nested_structure',
+ "[tag p] { [tag a] { [property color][operator :][keyword red]; } }");
+
+ MT('mixin',
+ "[def @mixin] [tag table-base] {}");
+
+ MT('number_without_semicolon',
+ "[tag p] {[property width][operator :][number 12]}",
+ "[tag a] {[property color][operator :][keyword red];}");
+
+ MT('atom_in_nested_block',
+ "[tag p] { [tag a] { [property color][operator :][atom #000]; } }");
+
+ MT('interpolation_in_property',
+ "[tag foo] { [operator #{][variable-2 $hello][operator }:][atom #000]; }");
+
+ MT('interpolation_in_selector',
+ "[tag foo][operator #{][variable-2 $hello][operator }] { [property color][operator :][atom #000]; }");
+
+ MT('interpolation_error',
+ "[tag foo][operator #{][error foo][operator }] { [property color][operator :][atom #000]; }");
+
+ MT("divide_operator",
+ "[tag foo] { [property width][operator :][number 4] [operator /] [number 2] }");
+})();
View
5 mode/css/test.js
@@ -1,6 +1,6 @@
(function() {
var mode = CodeMirror.getMode({tabSize: 4}, "css");
- function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 2)); }
+ function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
// Requires at least one media query
MT("atMediaEmpty",
@@ -103,4 +103,7 @@
MT("tagTwoProperties",
"[tag foo] { [property margin][operator :] [number 0]; [property padding][operator :] [number 0]; }");
+
+ MT("commentSGML",
+ "[comment <!--comment-->]");
})();
View
1  test/index.html
@@ -56,6 +56,7 @@
<script src="mode_test.js"></script>
<script src="../mode/css/css.js"></script>
<script src="../mode/css/test.js"></script>
+ <script src="../mode/css/scss_test.js"></script>
<script src="../mode/markdown/markdown.js"></script>
<script src="../mode/markdown/test.js"></script>
<script src="../mode/gfm/gfm.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.