From 671d2b94996ac71d56b2d05d5fe694ed7d84fa59 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Wed, 4 Apr 2012 12:27:35 -0700 Subject: upgrading to CodeMirror 2.23, since it has an important fix to Not close Ninja, if backspace is pressed while autocomplete dropdown is open. Signed-off-by: Ananya Sen --- imports/codemirror/mode/less/index.html | 39 ++++++--- imports/codemirror/mode/less/less.js | 143 +++++++++++++++++++------------- 2 files changed, 113 insertions(+), 69 deletions(-) (limited to 'imports/codemirror/mode/less') diff --git a/imports/codemirror/mode/less/index.html b/imports/codemirror/mode/less/index.html index bd3ef198..f7705205 100644 --- a/imports/codemirror/mode/less/index.html +++ b/imports/codemirror/mode/less/index.html @@ -7,23 +7,36 @@ +

CodeMirror: LESS mode

-

MIME types defined: text/less.

diff --git a/imports/codemirror/mode/less/less.js b/imports/codemirror/mode/less/less.js index dc584f02..1c20bd81 100644 --- a/imports/codemirror/mode/less/less.js +++ b/imports/codemirror/mode/less/less.js @@ -1,21 +1,26 @@ -CodeMirror.defineMode("less", function(config) { +/* +LESS mode - http://www.lesscss.org/ +Ported to CodeMirror by Peter Kroon +*/ + +CodeMirror.defineMode("css", function(config) { var indentUnit = config.indentUnit, type; function ret(style, tp) {type = tp; return style;} //html5 tags var tags = ["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","command","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","keygen","kbd","label","legend","li","link","map","mark","menu","meta","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"]; function inTagsArray(val){ - for(var i=0; i*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/] + else if (/[,+<>*\/]/.test(ch)) {//removed . dot character original was [,.+>*\/] return ret(null, "select-op"); } else if (/[;{}:\[\]()]/.test(ch)) { //added () char for lesscss original was [;{}:\[\]] if(ch == ":"){ - stream.eatWhile(/[active|hover|link|visited]/); - if( stream.current().match(/active|hover|link|visited/)){ - return ret("tag", "tag"); - }else{ - return ret(null, ch); - } - }else{ - return ret(null, ch); - } + stream.eatWhile(/[active|hover|link|visited]/); + if( stream.current().match(/active|hover|link|visited/)){ + return ret("tag", "tag"); + }else{ + return ret(null, ch); + } + }else{ + return ret(null, ch); + } } - else if (ch == ".") { // lesscss - stream.eatWhile(/[\a-zA-Z0-9\-_]/); + else if (ch == ".") { // lesscss + stream.eatWhile(/[\a-zA-Z0-9\-_]/); return ret("tag", "tag"); } - else if (ch == "#") { // lesscss - stream.match(/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/); - if(stream.current().length >1){ - if(stream.current().match(/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/) != null){ - return ret("number", "unit"); - }else{ + else if (ch == "#") { // lesscss + //we don't eat white-space, we want the hex color and or id only + stream.eatWhile(/[A-Za-z0-9]/); + //check if there is a proper hex color length e.g. #eee || #eeeEEE + if(stream.current().length ===4 || stream.current().length ===7){ + if(stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false) != null){//is there a valid hex color value present in the current stream + //when not a valid hex value, parse as id + if(stream.current().substring(1) != stream.current().match(/[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/,false))return ret("atom", "tag"); + //eat white-space + stream.eatSpace(); + //when hex value declaration doesn't end with [;,] but is does with a slash/cc comment treat it as an id, just like the other hex values that don't end with[;,] + if( /[\/<>.(){!$%^&*_\-\\?=+\|#'~`]/.test(stream.peek()) )return ret("atom", "tag"); + //#time { color: #aaa } + else if(stream.peek() == "}" )return ret("number", "unit"); + //we have a valid hex color value, parse as id whenever an element/class is defined after the hex(id) value e.g. #eee aaa || #eee .aaa + else if( /[a-zA-Z\\]/.test(stream.peek()) )return ret("atom", "tag"); + //when a hex value is on the end of a line, parse as id + else if(stream.eol())return ret("atom", "tag"); + //default + else return ret("number", "unit"); + }else{//when not a valid hexvalue in the current stream e.g. #footer + stream.eatWhile(/[\w\\\-]/); + return ret("atom", "tag"); + } + }else{ + stream.eatWhile(/[\w\\\-]/); + return ret("atom", "tag"); + } + } + else if (ch == "&") { stream.eatWhile(/[\w\-]/); - return ret("atom", "tag"); + return ret(null, ch); + } + else if (ch == "&") { + stream.eatWhile(/[\w\-]/); + return ret(null, ch); } - }else{ - stream.eatWhile(/[\w\-]/); - return ret("atom", "tag"); - } - } - else if (ch == "&") { - stream.eatWhile(/[\w\-]/); - return ret(null, ch); - } else { stream.eatWhile(/[\w\\\-_.%]/); - if( stream.eat("(") ){ // lesscss - return ret(null, ch); - }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... - return ret("number", "unit"); - }else if( inTagsArray(stream.current()) ){ // lesscss match html tags - return ret("tag", "tag"); - }else if( (stream.peek() == ")" || stream.peek() == "/") && stream.current().indexOf('.') !== -1){ - return ret("string", "string");//let url(logo.png) without quotes and froward slash return as string - }else{ + if( stream.peek().match(/\(/) != null ){// lesscss + stream.eatWhile(/[a-zA-Z\s]/); + if(stream.peek() == "(")return ret(null, ch); + }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... + return ret("number", "unit"); + }else if( inTagsArray(stream.current()) ){ // lesscss match html tags + return ret("tag", "tag"); + }else if( /\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")) && stream.current().indexOf(".") !== -1){ + return ret("string", "string");//let url(/images/logo.png) without quotes return as string + }else{ return ret("variable", "variable"); - } + } } } function tokenSComment(stream, state) {// SComment = Slash comment stream.skipToEnd(); - state.tokenize = tokenBase; + state.tokenize = tokenBase; return ret("comment", "comment"); } - + function tokenCComment(stream, state) { var maybeEnd = false, ch; while ((ch = stream.next()) != null) { @@ -146,7 +171,7 @@ CodeMirror.defineMode("less", function(config) { } return { - startState: function(base) { + startState: function(base) { return {tokenize: tokenBase, baseIndent: base || 0, stack: []}; @@ -160,7 +185,11 @@ CodeMirror.defineMode("less", function(config) { if (type == "hash" && context == "rule") style = "atom"; else if (style == "variable") { if (context == "rule") style = null; //"tag" - else if (!context || context == "@media{") style = "tag"; + else if (!context || context == "@media{"){ + style = stream.current() == "when" ? "variable" : + stream.string.match(/#/g) != undefined ? null : + /[\s,|\s\)]/.test(stream.peek()) ? "tag" : null; + } } if (context == "rule" && /^[\{\};]$/.test(type)) @@ -186,4 +215,4 @@ CodeMirror.defineMode("less", function(config) { }; }); -CodeMirror.defineMIME("text/less", "less"); +CodeMirror.defineMIME("text/css", "css"); -- cgit v1.2.3