aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/less
diff options
context:
space:
mode:
Diffstat (limited to 'imports/codemirror/mode/less')
-rw-r--r--imports/codemirror/mode/less/index.html25
-rw-r--r--imports/codemirror/mode/less/less.js42
2 files changed, 48 insertions, 19 deletions
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 @@
5 <link rel="stylesheet" href="../../lib/codemirror.css"> 5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script> 6 <script src="../../lib/codemirror.js"></script>
7 <script src="less.js"></script> 7 <script src="less.js"></script>
8 <style>.CodeMirror {background: #f8f8f8; border: 1px solid #ddd;}</style> 8 <style>.CodeMirror {background: #f8f8f8; border: 1px solid #ddd; font-size:12px} .CodeMirror-scroll {height: 400px}</style>
9 <link rel="stylesheet" href="../../doc/docs.css"> 9 <link rel="stylesheet" href="../../doc/docs.css">
10 <link rel="stylesheet" href="../../theme/lesser-dark.css"> 10 <link rel="stylesheet" href="../../theme/lesser-dark.css">
11 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 11 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -14,15 +14,28 @@
14 <h1>CodeMirror: LESS mode</h1> 14 <h1>CodeMirror: LESS mode</h1>
15 <form><textarea id="code" name="code">/* Some LESS code */ 15 <form><textarea id="code" name="code">/* Some LESS code */
16 16
17button {
18 width: 32px;
19 height: 32px;
20 border: 0;
21 margin: 4px;
22 cursor: pointer;
23}
24button.icon-plus { background: url(http://dahlström.net/tmp/sharp-icons/svg-icon-target.svg#plus) no-repeat; }
25button.icon-chart { background: url(http://dahlström.net/tmp/sharp-icons/svg-icon-target.svg#chart) no-repeat; }
26
27button:hover { background-color: #999; }
28button:active { background-color: #666; }
29
17@test_a: #eeeQQQ;//this is not a valid hex value and thus parsed as an element id 30@test_a: #eeeQQQ;//this is not a valid hex value and thus parsed as an element id
18@test_b: #eeeFFF//this is a valid hex value but the declaration doesn't end with a semicolon and thus parsed as an element id 31@test_b: #eeeFFF //this is a valid hex value but the declaration doesn't end with a semicolon and thus parsed as an element id
19 32
20#eee aaa .box 33#eee aaa .box
21{ 34{
22 #test bbb { 35 #test bbb {
23 width: 500px; 36 width: 500px;
24 height: 250px; 37 height: 250px;
25 background-image: url(sheep.png), url(betweengrassandsky.png); 38 background-image: url(dir/output/sheep.png), url( betweengrassandsky.png );
26 background-position: center bottom, left top; 39 background-position: center bottom, left top;
27 background-repeat: no-repeat; 40 background-repeat: no-repeat;
28 } 41 }
@@ -594,10 +607,12 @@ td {
594</textarea></form> 607</textarea></form>
595 <script> 608 <script>
596 var editor = CodeMirror.fromTextArea(document.getElementById("code"), { 609 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
597 theme: "lesser-dark" 610 theme: "lesser-dark",
611 lineNumbers : true,
612 matchBrackets : true
598 }); 613 });
599 </script> 614 </script>
600 615
601 <p><strong>MIME types defined:</strong> <code>text/less</code>.</p> 616 <p><strong>MIME types defined:</strong> <code>text/x-less</code>, <code>text/css</code> (if not previously defined).</p>
602 </body> 617 </body>
603</html> 618</html>
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/
3Ported to CodeMirror by Peter Kroon 3Ported to CodeMirror by Peter Kroon
4*/ 4*/
5 5
6CodeMirror.defineMode("css", function(config) { 6CodeMirror.defineMode("less", function(config) {
7 var indentUnit = config.indentUnit, type; 7 var indentUnit = config.indentUnit, type;
8 function ret(style, tp) {type = tp; return style;} 8 function ret(style, tp) {type = tp; return style;}
9 //html5 tags 9 //html5 tags
@@ -41,7 +41,7 @@ CodeMirror.defineMode("css", function(config) {
41 return tokenSComment(stream, state); 41 return tokenSComment(stream, state);
42 }else{ 42 }else{
43 stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/); 43 stream.eatWhile(/[\a-zA-Z0-9\-_.\s]/);
44 if(/\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string 44 if(/\/|\)|#/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")))return ret("string", "string");//let url(/images/logo.png) without quotes return as string
45 return ret("number", "unit"); 45 return ret("number", "unit");
46 } 46 }
47 } 47 }
@@ -105,21 +105,33 @@ CodeMirror.defineMode("css", function(config) {
105 stream.eatWhile(/[\w\-]/); 105 stream.eatWhile(/[\w\-]/);
106 return ret(null, ch); 106 return ret(null, ch);
107 } 107 }
108 else if (ch == "&") {
109 stream.eatWhile(/[\w\-]/);
110 return ret(null, ch);
111 }
112 else { 108 else {
113 stream.eatWhile(/[\w\\\-_.%]/); 109 stream.eatWhile(/[\w\\\-_%.{]/);
114 if( stream.peek().match(/\(/) != null ){// lesscss 110 if(stream.current().match(/http|https/) != null){
115 stream.eatWhile(/[a-zA-Z\s]/); 111 stream.eatWhile(/[\w\\\-_%.{:\/]/);
116 if(stream.peek() == "(")return ret(null, ch); 112 return ret("string", "string");
117 }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... 113 }else if(stream.peek() == "<" || stream.peek() == ">"){
118 return ret("number", "unit"); 114 return ret("tag", "tag");
115 }else if( stream.peek().match(/\(/) != null ){// lessc
116 return ret(null, ch);
117 }else if (stream.peek() == "/" && state.stack[state.stack.length-1] != undefined){ // url(dir/center/image.png)
118 return ret("string", "string");
119 }else if( stream.current().match(/\-\d|\-.\d/) ){ // lesscss match e.g.: -5px -0.4 etc... only colorize the minus sign
120 //stream.backUp(stream.current().length-1); //commment out these 2 comment if you want the minus sign to be parsed as null -500px
121 //return ret(null, ch);
122 return ret("number", "unit");
119 }else if( inTagsArray(stream.current()) ){ // lesscss match html tags 123 }else if( inTagsArray(stream.current()) ){ // lesscss match html tags
120 return ret("tag", "tag"); 124 return ret("tag", "tag");
121 }else if( /\/|\)/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == ")")) && stream.current().indexOf(".") !== -1){ 125 }else if( /\/|[\s\)]/.test(stream.peek() || stream.eol() || (stream.eatSpace() && stream.peek() == "/")) && stream.current().indexOf(".") !== -1){
126 if(stream.current().substring(stream.current().length-1,stream.current().length) == "{"){
127 stream.backUp(1);
128 return ret("tag", "tag");
129 }//end if
130 if( (stream.eatSpace() && stream.peek().match(/[{<>.a-zA-Z]/) != null) || stream.eol() )return ret("tag", "tag");//e.g. button.icon-plus
122 return ret("string", "string");//let url(/images/logo.png) without quotes return as string 131 return ret("string", "string");//let url(/images/logo.png) without quotes return as string
132 }else if( stream.eol() ){
133 if(stream.current().substring(stream.current().length-1,stream.current().length) == "{")stream.backUp(1);
134 return ret("tag", "tag");
123 }else{ 135 }else{
124 return ret("variable", "variable"); 136 return ret("variable", "variable");
125 } 137 }
@@ -215,4 +227,6 @@ CodeMirror.defineMode("css", function(config) {
215 }; 227 };
216}); 228});
217 229
218CodeMirror.defineMIME("text/css", "css"); 230CodeMirror.defineMIME("text/x-less", "less");
231if (!CodeMirror.mimeModes.hasOwnProperty("text/css"))
232 CodeMirror.defineMIME("text/css", "less");