From 0e04fff0ea80fa5cbe96b8354db38bd334aea83a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Jul 2012 16:04:05 -0700 Subject: upgrade to codemirror 2.3 Signed-off-by: Ananya Sen Conflicts: js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css Signed-off-by: Ananya Sen --- imports/codemirror/mode/less/index.html | 25 ++++++++++++++++---- imports/codemirror/mode/less/less.js | 42 ++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 19 deletions(-) (limited to 'imports/codemirror/mode/less') diff --git a/imports/codemirror/mode/less/index.html b/imports/codemirror/mode/less/index.html index f7705205..cad8e4b2 100644 --- a/imports/codemirror/mode/less/index.html +++ b/imports/codemirror/mode/less/index.html @@ -5,7 +5,7 @@ - + @@ -14,15 +14,28 @@

CodeMirror: LESS mode

-

MIME types defined: text/less.

+

MIME types defined: text/x-less, text/css (if not previously defined).

diff --git a/imports/codemirror/mode/less/less.js b/imports/codemirror/mode/less/less.js index 1c20bd81..51163890 100644 --- a/imports/codemirror/mode/less/less.js +++ b/imports/codemirror/mode/less/less.js @@ -3,7 +3,7 @@ LESS mode - http://www.lesscss.org/ Ported to CodeMirror by Peter Kroon */ -CodeMirror.defineMode("css", function(config) { +CodeMirror.defineMode("less", function(config) { var indentUnit = config.indentUnit, type; function ret(style, tp) {type = tp; return style;} //html5 tags @@ -41,7 +41,7 @@ CodeMirror.defineMode("css", function(config) { return tokenSComment(stream, state); }else{ stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/); - if(/\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string + if(/\/|\)|#/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string return ret("number", "unit"); } } @@ -105,21 +105,33 @@ CodeMirror.defineMode("css", function(config) { stream.eatWhile(/[\w\-]/); return ret(null, ch); } - else if (ch == "&") { - stream.eatWhile(/[\w\-]/); - return ret(null, ch); - } else { - stream.eatWhile(/[\w\\\-_.%]/); - 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"); + stream.eatWhile(/[\w\\\-_%.{]/); + if(stream.current().match(/http|https/) != null){ + stream.eatWhile(/[\w\\\-_%.{:\/]/); + return ret("string", "string"); + }else if(stream.peek() == "<" || stream.peek() == ">"){ + return ret("tag", "tag"); + }else if( stream.peek().match(/\(/) != null ){// lessc + return ret(null, ch); + }else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png) + return ret("string", "string"); + }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... only colorize the minus sign + //stream.backUp(stream.current().length-1); //commment out these 2 comment if you want the minus sign to be parsed as null -500px + //return ret(null, ch); + 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){ + }else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){ + if(stream.current().substring(stream.current().length-1,stream.current().length) == "{"){ + stream.backUp(1); + return ret("tag", "tag"); + }//end if + if( (stream.eatSpace() && stream.peek().match(/[{<>.a-zA-Z]/) != null) || stream.eol() )return ret("tag", "tag");//e.g. button.icon-plus return ret("string", "string");//let url(/images/logo.png) without quotes return as string + }else if( stream.eol() ){ + if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1); + return ret("tag", "tag"); }else{ return ret("variable", "variable"); } @@ -215,4 +227,6 @@ CodeMirror.defineMode("css", function(config) { }; }); -CodeMirror.defineMIME("text/css", "css"); +CodeMirror.defineMIME("text/x-less", "less"); +if (!CodeMirror.mimeModes.hasOwnProperty("text/css")) + CodeMirror.defineMIME("text/css", "less"); -- cgit v1.2.3