Differential D134 Diff 321 branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/css/css.js
Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/css/css.js
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | LF |
CodeMirror.defineMode("css", function(config) { | CodeMirror.defineMode("css", function(config) { | ||||
var indentUnit = config.indentUnit, type; | var indentUnit = config.indentUnit, type; | ||||
function ret(style, tp) {type = tp; return style;} | function ret(style, tp) {type = tp; return style;} | ||||
function tokenBase(stream, state) { | function tokenBase(stream, state) { | ||||
var ch = stream.next(); | var ch = stream.next(); | ||||
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());} | if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());} | ||||
else if (ch == "/" && stream.eat("*")) { | else if (ch == "/" && stream.eat("*")) { | ||||
state.tokenize = tokenCComment; | state.tokenize = tokenCComment; | ||||
return tokenCComment(stream, state); | return tokenCComment(stream, state); | ||||
} | } | ||||
else if (ch == "<" && stream.eat("!")) { | else if (ch == "<" && stream.eat("!")) { | ||||
state.tokenize = tokenSGMLComment; | state.tokenize = tokenSGMLComment; | ||||
return tokenSGMLComment(stream, state); | return tokenSGMLComment(stream, state); | ||||
} | } | ||||
else if (ch == "=") ret(null, "compare"); | else if (ch == "=") ret(null, "compare"); | ||||
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare"); | else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare"); | ||||
else if (ch == "\"" || ch == "'") { | else if (ch == "\"" || ch == "'") { | ||||
state.tokenize = tokenString(ch); | state.tokenize = tokenString(ch); | ||||
return state.tokenize(stream, state); | return state.tokenize(stream, state); | ||||
} | } | ||||
else if (ch == "#") { | else if (ch == "#") { | ||||
stream.eatWhile(/[\w\\\-]/); | stream.eatWhile(/[\w\\\-]/); | ||||
return ret("atom", "hash"); | return ret("atom", "hash"); | ||||
} | } | ||||
else if (ch == "!") { | else if (ch == "!") { | ||||
stream.match(/^\s*\w*/); | stream.match(/^\s*\w*/); | ||||
return ret("keyword", "important"); | return ret("keyword", "important"); | ||||
} | } | ||||
else if (/\d/.test(ch)) { | else if (/\d/.test(ch)) { | ||||
stream.eatWhile(/[\w.%]/); | stream.eatWhile(/[\w.%]/); | ||||
return ret("number", "unit"); | return ret("number", "unit"); | ||||
} | } | ||||
else if (/[,.+>*\/]/.test(ch)) { | else if (/[,.+>*\/]/.test(ch)) { | ||||
return ret(null, "select-op"); | return ret(null, "select-op"); | ||||
} | } | ||||
else if (/[;{}:\[\]]/.test(ch)) { | else if (/[;{}:\[\]]/.test(ch)) { | ||||
return ret(null, ch); | return ret(null, ch); | ||||
} | } | ||||
else { | else { | ||||
stream.eatWhile(/[\w\\\-]/); | stream.eatWhile(/[\w\\\-]/); | ||||
return ret("variable", "variable"); | return ret("variable", "variable"); | ||||
} | } | ||||
} | } | ||||
function tokenCComment(stream, state) { | function tokenCComment(stream, state) { | ||||
var maybeEnd = false, ch; | var maybeEnd = false, ch; | ||||
while ((ch = stream.next()) != null) { | while ((ch = stream.next()) != null) { | ||||
if (maybeEnd && ch == "/") { | if (maybeEnd && ch == "/") { | ||||
state.tokenize = tokenBase; | state.tokenize = tokenBase; | ||||
break; | break; | ||||
} | } | ||||
maybeEnd = (ch == "*"); | maybeEnd = (ch == "*"); | ||||
} | } | ||||
return ret("comment", "comment"); | return ret("comment", "comment"); | ||||
} | } | ||||
function tokenSGMLComment(stream, state) { | function tokenSGMLComment(stream, state) { | ||||
var dashes = 0, ch; | var dashes = 0, ch; | ||||
while ((ch = stream.next()) != null) { | while ((ch = stream.next()) != null) { | ||||
if (dashes >= 2 && ch == ">") { | if (dashes >= 2 && ch == ">") { | ||||
state.tokenize = tokenBase; | state.tokenize = tokenBase; | ||||
break; | break; | ||||
} | } | ||||
dashes = (ch == "-") ? dashes + 1 : 0; | dashes = (ch == "-") ? dashes + 1 : 0; | ||||
} | } | ||||
return ret("comment", "comment"); | return ret("comment", "comment"); | ||||
} | } | ||||
function tokenString(quote) { | function tokenString(quote) { | ||||
return function(stream, state) { | return function(stream, state) { | ||||
var escaped = false, ch; | var escaped = false, ch; | ||||
while ((ch = stream.next()) != null) { | while ((ch = stream.next()) != null) { | ||||
if (ch == quote && !escaped) | if (ch == quote && !escaped) | ||||
break; | break; | ||||
escaped = !escaped && ch == "\\"; | escaped = !escaped && ch == "\\"; | ||||
} | } | ||||
if (!escaped) state.tokenize = tokenBase; | if (!escaped) state.tokenize = tokenBase; | ||||
return ret("string", "string"); | return ret("string", "string"); | ||||
}; | }; | ||||
} | } | ||||
return { | return { | ||||
startState: function(base) { | startState: function(base) { | ||||
return {tokenize: tokenBase, | return {tokenize: tokenBase, | ||||
baseIndent: base || 0, | baseIndent: base || 0, | ||||
stack: []}; | stack: []}; | ||||
}, | }, | ||||
token: function(stream, state) { | token: function(stream, state) { | ||||
if (stream.eatSpace()) return null; | if (stream.eatSpace()) return null; | ||||
var style = state.tokenize(stream, state); | var style = state.tokenize(stream, state); | ||||
var context = state.stack[state.stack.length-1]; | var context = state.stack[state.stack.length-1]; | ||||
if (type == "hash" && context != "rule") style = "string-2"; | if (type == "hash" && context != "rule") style = "string-2"; | ||||
else if (style == "variable") { | else if (style == "variable") { | ||||
if (context == "rule") style = "number"; | if (context == "rule") style = "number"; | ||||
else if (!context || context == "@media{") style = "tag"; | else if (!context || context == "@media{") style = "tag"; | ||||
} | } | ||||
if (context == "rule" && /^[\{\};]$/.test(type)) | if (context == "rule" && /^[\{\};]$/.test(type)) | ||||
state.stack.pop(); | state.stack.pop(); | ||||
if (type == "{") { | if (type == "{") { | ||||
if (context == "@media") state.stack[state.stack.length-1] = "@media{"; | if (context == "@media") state.stack[state.stack.length-1] = "@media{"; | ||||
else state.stack.push("{"); | else state.stack.push("{"); | ||||
} | } | ||||
else if (type == "}") state.stack.pop(); | else if (type == "}") state.stack.pop(); | ||||
else if (type == "@media") state.stack.push("@media"); | else if (type == "@media") state.stack.push("@media"); | ||||
else if (context == "{" && type != "comment") state.stack.push("rule"); | else if (context == "{" && type != "comment") state.stack.push("rule"); | ||||
return style; | return style; | ||||
}, | }, | ||||
indent: function(state, textAfter) { | indent: function(state, textAfter) { | ||||
var n = state.stack.length; | var n = state.stack.length; | ||||
if (/^\}/.test(textAfter)) | if (/^\}/.test(textAfter)) | ||||
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1; | n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1; | ||||
return state.baseIndent + n * indentUnit; | return state.baseIndent + n * indentUnit; | ||||
}, | }, | ||||
electricChars: "}" | electricChars: "}" | ||||
}; | }; | ||||
}); | }); | ||||
CodeMirror.defineMIME("text/css", "css"); | CodeMirror.defineMIME("text/css", "css"); |