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/clike/clike.js | 39 +- imports/codemirror/mode/clike/scala.html | 765 +++++++++++++++++++++ .../codemirror/mode/coffeescript/coffeescript.js | 6 + imports/codemirror/mode/coffeescript/index.html | 6 + imports/codemirror/mode/diff/diff.css | 3 - imports/codemirror/mode/diff/diff.js | 29 +- imports/codemirror/mode/diff/index.html | 13 +- imports/codemirror/mode/ecl/ecl.js | 2 +- imports/codemirror/mode/erlang/erlang.js | 251 +++++++ imports/codemirror/mode/erlang/index.html | 61 ++ imports/codemirror/mode/gfm/gfm.js | 42 +- .../codemirror/mode/htmlembedded/htmlembedded.js | 2 +- imports/codemirror/mode/htmlmixed/htmlmixed.js | 4 +- imports/codemirror/mode/javascript/javascript.js | 9 +- imports/codemirror/mode/less/index.html | 25 +- imports/codemirror/mode/less/less.js | 42 +- imports/codemirror/mode/markdown/markdown.js | 2 +- imports/codemirror/mode/php/php.js | 2 +- imports/codemirror/mode/pig/index.html | 42 ++ imports/codemirror/mode/pig/pig.js | 172 +++++ imports/codemirror/mode/python/python.js | 30 +- imports/codemirror/mode/rst/rst.js | 2 +- imports/codemirror/mode/ruby/ruby.js | 11 +- imports/codemirror/mode/scheme/scheme.js | 120 ++-- imports/codemirror/mode/shell/index.html | 50 ++ imports/codemirror/mode/shell/shell.js | 103 +++ imports/codemirror/mode/stex/stex.js | 10 +- imports/codemirror/mode/stex/test.html | 12 + imports/codemirror/mode/tiddlywiki/tiddlywiki.css | 35 +- imports/codemirror/mode/tiddlywiki/tiddlywiki.js | 28 +- imports/codemirror/mode/tiki/index.html | 82 +++ imports/codemirror/mode/tiki/tiki.css | 26 + imports/codemirror/mode/tiki/tiki.js | 316 +++++++++ imports/codemirror/mode/xml/xml.js | 69 +- imports/codemirror/mode/xmlpure/index.html | 58 -- imports/codemirror/mode/xmlpure/xmlpure.js | 490 ------------- 36 files changed, 2251 insertions(+), 708 deletions(-) create mode 100644 imports/codemirror/mode/clike/scala.html delete mode 100644 imports/codemirror/mode/diff/diff.css create mode 100644 imports/codemirror/mode/erlang/erlang.js create mode 100644 imports/codemirror/mode/erlang/index.html create mode 100644 imports/codemirror/mode/pig/index.html create mode 100644 imports/codemirror/mode/pig/pig.js create mode 100644 imports/codemirror/mode/shell/index.html create mode 100644 imports/codemirror/mode/shell/shell.js create mode 100644 imports/codemirror/mode/tiki/index.html create mode 100644 imports/codemirror/mode/tiki/tiki.css create mode 100644 imports/codemirror/mode/tiki/tiki.js delete mode 100644 imports/codemirror/mode/xmlpure/index.html delete mode 100644 imports/codemirror/mode/xmlpure/xmlpure.js (limited to 'imports/codemirror/mode') diff --git a/imports/codemirror/mode/clike/clike.js b/imports/codemirror/mode/clike/clike.js index 66443fb8..0e7f48b6 100644 --- a/imports/codemirror/mode/clike/clike.js +++ b/imports/codemirror/mode/clike/clike.js @@ -21,7 +21,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { } if (/[\[\]{}\(\),;\:\.]/.test(ch)) { curPunc = ch; - return null + return null; } if (/\d/.test(ch)) { stream.eatWhile(/[\w\.]/); @@ -231,4 +231,41 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { } } }); + CodeMirror.defineMIME("text/x-scala", { + name: "clike", + keywords: words( + + /* scala */ + "abstract case catch class def do else extends false final finally for forSome if " + + "implicit import lazy match new null object override package private protected return " + + "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " + + "<% >: # @ " + + + /* package scala */ + "assert assume require print println printf readLine readBoolean readByte readShort " + + "readChar readInt readLong readFloat readDouble " + + + "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " + + "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " + + "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " + + "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " + + "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " + + + /* package java.lang */ + "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " + + "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + + "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + + "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" + + + ), + blockKeywords: words("catch class do else finally for forSome if match switch try while"), + atoms: words("true false null"), + hooks: { + "@": function(stream, state) { + stream.eatWhile(/[\w\$_]/); + return "meta"; + } + } + }); }()); diff --git a/imports/codemirror/mode/clike/scala.html b/imports/codemirror/mode/clike/scala.html new file mode 100644 index 00000000..5fdd84ed --- /dev/null +++ b/imports/codemirror/mode/clike/scala.html @@ -0,0 +1,765 @@ + + + + CodeMirror: C-like mode + + + + + + + + +
+ +
+ + + + diff --git a/imports/codemirror/mode/coffeescript/coffeescript.js b/imports/codemirror/mode/coffeescript/coffeescript.js index 4f2bd66d..dece5f8a 100644 --- a/imports/codemirror/mode/coffeescript/coffeescript.js +++ b/imports/codemirror/mode/coffeescript/coffeescript.js @@ -60,6 +60,12 @@ CodeMirror.defineMode('coffeescript', function(conf) { var ch = stream.peek(); + // Handle docco title comment (single line) + if (stream.match("####")) { + stream.skipToEnd(); + return 'comment'; + } + // Handle multi line comments if (stream.match("###")) { state.tokenize = longComment; diff --git a/imports/codemirror/mode/coffeescript/index.html b/imports/codemirror/mode/coffeescript/index.html index 127c4bf9..98bd4971 100644 --- a/imports/codemirror/mode/coffeescript/index.html +++ b/imports/codemirror/mode/coffeescript/index.html @@ -46,12 +46,18 @@ root = this # Save the previous value of the `_` variable. previousUnderscore = root._ +### Multiline + comment +### # Establish the object that gets thrown to break out of a loop iteration. # `StopIteration` is SOP on Mozilla. breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration +#### Docco style single line comment (title) + + # Helper function to escape **RegExp** contents, because JS doesn't have one. escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') diff --git a/imports/codemirror/mode/diff/diff.css b/imports/codemirror/mode/diff/diff.css deleted file mode 100644 index 0e96ab21..00000000 --- a/imports/codemirror/mode/diff/diff.css +++ /dev/null @@ -1,3 +0,0 @@ -span.cm-rangeinfo {color: #a0b;} -span.cm-minus {color: red;} -span.cm-plus {color: #2b2;} diff --git a/imports/codemirror/mode/diff/diff.js b/imports/codemirror/mode/diff/diff.js index 725bb2c7..3402f3b3 100644 --- a/imports/codemirror/mode/diff/diff.js +++ b/imports/codemirror/mode/diff/diff.js @@ -1,11 +1,30 @@ CodeMirror.defineMode("diff", function() { + + var TOKEN_NAMES = { + '+': 'tag', + '-': 'string', + '@': 'meta' + }; + return { token: function(stream) { - var ch = stream.next(); - stream.skipToEnd(); - if (ch == "+") return "plus"; - if (ch == "-") return "minus"; - if (ch == "@") return "rangeinfo"; + var tw_pos = stream.string.search(/[\t ]+?$/); + + if (!stream.sol() || tw_pos === 0) { + stream.skipToEnd(); + return ("error " + ( + TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, ''); + } + + var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd(); + + if (tw_pos === -1) { + stream.skipToEnd(); + } else { + stream.pos = tw_pos; + } + + return token_name; } }; }); diff --git a/imports/codemirror/mode/diff/index.html b/imports/codemirror/mode/diff/index.html index 2540236c..b102c090 100644 --- a/imports/codemirror/mode/diff/index.html +++ b/imports/codemirror/mode/diff/index.html @@ -5,8 +5,13 @@ - - + @@ -34,12 +39,12 @@ index 04646a9..9a39cc7 100644 } function onMouseDown(e) { -- var start = posFromMouse(e), last = start; +- var start = posFromMouse(e), last = start; + var start = posFromMouse(e), last = start, target = e.target(); if (!start) return; setCursor(start.line, start.ch, false); if (e.button() != 1) return; -+ if (target.parentNode == gutter) { ++ if (target.parentNode == gutter) { + if (options.onGutterClick) + options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom); + return; diff --git a/imports/codemirror/mode/ecl/ecl.js b/imports/codemirror/mode/ecl/ecl.js index 9c94e670..57c8554e 100644 --- a/imports/codemirror/mode/ecl/ecl.js +++ b/imports/codemirror/mode/ecl/ecl.js @@ -200,4 +200,4 @@ CodeMirror.defineMode("ecl", function(config) { }; }); -CodeMirror.defineMIME("text/x-ecl"); +CodeMirror.defineMIME("text/x-ecl", "ecl"); diff --git a/imports/codemirror/mode/erlang/erlang.js b/imports/codemirror/mode/erlang/erlang.js new file mode 100644 index 00000000..5c094f8e --- /dev/null +++ b/imports/codemirror/mode/erlang/erlang.js @@ -0,0 +1,251 @@ +// erlang -> CodeMirror tag +// +// atom -> atom +// attribute -> attribute +// builtin -> builtin +// comment -> comment +// error -> error +// fun -> meta +// function -> tag +// guard -> property +// keyword -> keyword +// macro -> variable-2 +// number -> number +// operator -> operator +// record -> bracket +// string -> string +// type -> def +// variable -> variable + +CodeMirror.defineMIME("text/x-erlang", "erlang"); + +CodeMirror.defineMode("erlang", function(cmCfg, modeCfg) { + + var typeWords = [ + "-type", "-spec", "-export_type", "-opaque"]; + + var keywordWords = [ + "after","begin","catch","case","cond","end","fun","if", + "let","of","query","receive","try","when"]; + + var operatorWords = [ + "and","andalso","band","bnot","bor","bsl","bsr","bxor", + "div","not","or","orelse","rem","xor"]; + + var operatorSymbols = [ + "+","-","*","/",">",">=","<","=<","=:=","==","=/=","/=","||","<-"]; + + var guardWords = [ + "is_atom","is_binary","is_bitstring","is_boolean","is_float", + "is_function","is_integer","is_list","is_number","is_pid", + "is_port","is_record","is_reference","is_tuple", + "atom","binary","bitstring","boolean","function","integer","list", + "number","pid","port","record","reference","tuple"]; + + var bifWords = [ + "abs","adler32","adler32_combine","alive","apply","atom_to_binary", + "atom_to_list","binary_to_atom","binary_to_existing_atom", + "binary_to_list","binary_to_term","bit_size","bitstring_to_list", + "byte_size","check_process_code","contact_binary","crc32", + "crc32_combine","date","decode_packet","delete_module", + "disconnect_node","element","erase","exit","float","float_to_list", + "garbage_collect","get","get_keys","group_leader","halt","hd", + "integer_to_list","internal_bif","iolist_size","iolist_to_binary", + "is_alive","is_atom","is_binary","is_bitstring","is_boolean", + "is_float","is_function","is_integer","is_list","is_number","is_pid", + "is_port","is_process_alive","is_record","is_reference","is_tuple", + "length","link","list_to_atom","list_to_binary","list_to_bitstring", + "list_to_existing_atom","list_to_float","list_to_integer", + "list_to_pid","list_to_tuple","load_module","make_ref","module_loaded", + "monitor_node","node","node_link","node_unlink","nodes","notalive", + "now","open_port","pid_to_list","port_close","port_command", + "port_connect","port_control","pre_loaded","process_flag", + "process_info","processes","purge_module","put","register", + "registered","round","self","setelement","size","spawn","spawn_link", + "spawn_monitor","spawn_opt","split_binary","statistics", + "term_to_binary","time","throw","tl","trunc","tuple_size", + "tuple_to_list","unlink","unregister","whereis"]; + + function isMember(element,list) { + return (-1 < list.indexOf(element)); + } + + function isPrev(stream,string) { + var start = stream.start; + var len = string.length; + if (len <= start) { + var word = stream.string.slice(start-len,start); + return word == string; + }else{ + return false; + } + } + + var smallRE = /[a-z_]/; + var largeRE = /[A-Z_]/; + var digitRE = /[0-9]/; + var octitRE = /[0-7]/; + var idRE = /[a-z_A-Z0-9]/; + + function tokenize(stream, state) { + if (stream.eatSpace()) { + return null; + } + + // attributes and type specs + if (stream.sol() && stream.peek() == '-') { + stream.next(); + if (stream.eat(smallRE) && stream.eatWhile(idRE)) { + if (stream.peek() == "(") { + return "attribute"; + }else if (isMember(stream.current(),typeWords)) { + return "def"; + }else{ + return null; + } + } + stream.backUp(1); + } + + var ch = stream.next(); + + // comment + if (ch == '%') { + stream.skipToEnd(); + return "comment"; + } + + // macro + if (ch == '?') { + stream.eatWhile(idRE); + return "variable-2"; + } + + // record + if ( ch == "#") { + stream.eatWhile(idRE); + return "bracket"; + } + + // char + if ( ch == "$") { + if (stream.next() == "\\") { + if (!stream.eatWhile(octitRE)) { + stream.next(); + } + } + return "string"; + } + + // quoted atom + if (ch == '\'') { + return singleQuote(stream); + } + + // string + if (ch == '"') { + return doubleQuote(stream); + } + + // variable + if (largeRE.test(ch)) { + stream.eatWhile(idRE); + return "variable"; + } + + // atom/keyword/BIF/function + if (smallRE.test(ch)) { + stream.eatWhile(idRE); + + if (stream.peek() == "/") { + stream.next(); + if (stream.eatWhile(digitRE)) { + return "meta"; // f/0 style fun + }else{ + stream.backUp(1); + return "atom"; + } + } + + var w = stream.current(); + + if (isMember(w,keywordWords)) { + return "keyword"; // keyword + } + if (stream.peek() == "(") { + if (isMember(w,bifWords) && + (!isPrev(stream,":") || isPrev(stream,"erlang:"))) { + return "builtin"; // BIF + }else{ + return "tag"; // function + } + } + if (isMember(w,guardWords)) { + return "property"; // guard + } + if (isMember(w,operatorWords)) { + return "operator"; // operator + } + + + if (stream.peek() == ":") { + if (w == "erlang") { // f:now() is highlighted incorrectly + return "builtin"; + } else { + return "tag"; // function application + } + } + + return "atom"; + } + + // number + if (digitRE.test(ch)) { + stream.eatWhile(digitRE); + if (stream.eat('#')) { + stream.eatWhile(digitRE); // 16#10 style integer + } else { + if (stream.eat('.')) { // float + stream.eatWhile(digitRE); + } + if (stream.eat(/[eE]/)) { + stream.eat(/[-+]/); // float with exponent + stream.eatWhile(digitRE); + } + } + return "number"; // normal integer + } + + return null; + } + + function doubleQuote(stream) { + return Quote(stream, '"', '\\', "string"); + } + + function singleQuote(stream) { + return Quote(stream,'\'','\\',"atom"); + } + + function Quote(stream,quoteChar,escapeChar,tag) { + while (!stream.eol()) { + var ch = stream.next(); + if (ch == quoteChar) { + return tag; + }else if (ch == escapeChar) { + stream.next(); + } + } + return "error"; + } + + return { + startState: function() { + return {}; + }, + + token: function(stream, state) { + return tokenize(stream, state); + } + }; +}); diff --git a/imports/codemirror/mode/erlang/index.html b/imports/codemirror/mode/erlang/index.html new file mode 100644 index 00000000..625491f2 --- /dev/null +++ b/imports/codemirror/mode/erlang/index.html @@ -0,0 +1,61 @@ + + + + CodeMirror: Erlang mode + + + + + + + + +

CodeMirror: Erlang mode

+ +
+ + + +

MIME types defined: text/x-erlang.

+ + diff --git a/imports/codemirror/mode/gfm/gfm.js b/imports/codemirror/mode/gfm/gfm.js index 01afed7b..8f457c53 100644 --- a/imports/codemirror/mode/gfm/gfm.js +++ b/imports/codemirror/mode/gfm/gfm.js @@ -69,7 +69,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) { function handleText(stream, mdState) { var match; if (stream.match(/^\w+:\/\/\S+/)) { - return 'linkhref'; + return 'link'; } if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) { return mdMode.getType(mdState); @@ -102,7 +102,43 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) { }, token: function(stream, state) { - return state.token(stream, state); + /* Parse GFM double bracket links */ + if ((ch = stream.peek()) != undefined && ch == '[') { + stream.next(); // Advance the stream + + /* Only handle double bracket links */ + if ((ch = stream.peek()) == undefined || ch != '[') { + stream.backUp(1); + return state.token(stream, state); + } + + while ((ch = stream.next()) != undefined && ch != ']') {} + + if (ch == ']' && (ch = stream.next()) != undefined && ch == ']') + return 'link'; + + /* If we did not find the second ']' */ + stream.backUp(1); + } + + /* Match GFM latex formulas, as well as latex formulas within '$' */ + if (stream.match(/^\$[^\$]+\$/)) { + return "string"; + } + + if (stream.match(/^\\\((.*?)\\\)/)) { + return "string"; + } + + if (stream.match(/^\$\$[^\$]+\$\$/)) { + return "string"; + } + + if (stream.match(/^\\\[(.*?)\\\]/)) { + return "string"; + } + + return state.token(stream, state); } } -}); +}, "markdown"); diff --git a/imports/codemirror/mode/htmlembedded/htmlembedded.js b/imports/codemirror/mode/htmlembedded/htmlembedded.js index 08e170ea..1773aeb5 100644 --- a/imports/codemirror/mode/htmlembedded/htmlembedded.js +++ b/imports/codemirror/mode/htmlembedded/htmlembedded.js @@ -61,7 +61,7 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) { electricChars: "/{}:" } -}); +}, "htmlmixed"); CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"}); CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"}); diff --git a/imports/codemirror/mode/htmlmixed/htmlmixed.js b/imports/codemirror/mode/htmlmixed/htmlmixed.js index c66a6583..a6c62c9d 100644 --- a/imports/codemirror/mode/htmlmixed/htmlmixed.js +++ b/imports/codemirror/mode/htmlmixed/htmlmixed.js @@ -73,11 +73,13 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) { }, compareStates: function(a, b) { + if (a.mode != b.mode) return false; + if (a.localState) return CodeMirror.Pass; return htmlMode.compareStates(a.htmlState, b.htmlState); }, electricChars: "/{}:" } -}); +}, "xml", "javascript", "css"); CodeMirror.defineMIME("text/html", "htmlmixed"); diff --git a/imports/codemirror/mode/javascript/javascript.js b/imports/codemirror/mode/javascript/javascript.js index 462f4863..65f11c5b 100644 --- a/imports/codemirror/mode/javascript/javascript.js +++ b/imports/codemirror/mode/javascript/javascript.js @@ -54,7 +54,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { stream.eatWhile(/[\da-f]/i); return ret("number", "number"); } - else if (/\d/.test(ch)) { + else if (/\d/.test(ch) || ch == "-" && stream.eat(/\d/)) { stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); return ret("number", "number"); } @@ -243,7 +243,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { function maybeoperator(type, value) { if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); - if (type == "operator") return cont(expression); + if (type == "operator" || type == ":") return cont(expression); if (type == ";") return; if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator); if (type == ".") return cont(property, maybeoperator); @@ -341,8 +341,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { indent: function(state, textAfter) { if (state.tokenize != jsTokenBase) return 0; - var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, - type = lexical.type, closing = firstChar == type; + var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; + if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; + var type = lexical.type, closing = firstChar == type; if (type == "vardef") return lexical.indented + 4; else if (type == "form" && firstChar == "{") return lexical.indented; else if (type == "stat" || type == "form") return lexical.indented + indentUnit; 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"); diff --git a/imports/codemirror/mode/markdown/markdown.js b/imports/codemirror/mode/markdown/markdown.js index af95753e..232ced78 100644 --- a/imports/codemirror/mode/markdown/markdown.js +++ b/imports/codemirror/mode/markdown/markdown.js @@ -240,6 +240,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { getType: getType }; -}); +}, "xml"); CodeMirror.defineMIME("text/x-markdown", "markdown"); diff --git a/imports/codemirror/mode/php/php.js b/imports/codemirror/mode/php/php.js index 5406a5ce..e35922fd 100644 --- a/imports/codemirror/mode/php/php.js +++ b/imports/codemirror/mode/php/php.js @@ -143,7 +143,7 @@ electricChars: "/{}:" } - }); + }, "xml", "clike", "javascript", "css"); CodeMirror.defineMIME("application/x-httpd-php", "php"); CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true}); CodeMirror.defineMIME("text/x-php", phpConfig); diff --git a/imports/codemirror/mode/pig/index.html b/imports/codemirror/mode/pig/index.html new file mode 100644 index 00000000..9cd69c4f --- /dev/null +++ b/imports/codemirror/mode/pig/index.html @@ -0,0 +1,42 @@ + + + + CodeMirror: Pig Latin mode + + + + + + + +

CodeMirror: Pig Latin mode

+ +
+ + + +

+ Simple mode that handles Pig Latin language. +

+ +

MIME type defined: text/x-pig + (PIG code) + diff --git a/imports/codemirror/mode/pig/pig.js b/imports/codemirror/mode/pig/pig.js new file mode 100644 index 00000000..b7399b43 --- /dev/null +++ b/imports/codemirror/mode/pig/pig.js @@ -0,0 +1,172 @@ +/* + * Pig Latin Mode for CodeMirror 2 + * @author Prasanth Jayachandran + * @link https://github.com/prasanthj/pig-codemirror-2 + * This implementation is adapted from PL/SQL mode in CodeMirror 2. +*/ +CodeMirror.defineMode("pig", function(config, parserConfig) { + var indentUnit = config.indentUnit, + keywords = parserConfig.keywords, + builtins = parserConfig.builtins, + types = parserConfig.types, + multiLineStrings = parserConfig.multiLineStrings; + + var isOperatorChar = /[*+\-%<>=&?:\/!|]/; + + function chain(stream, state, f) { + state.tokenize = f; + return f(stream, state); + } + + var type; + function ret(tp, style) { + type = tp; + return style; + } + + function tokenComment(stream, state) { + var isEnd = false; + var ch; + while(ch = stream.next()) { + if(ch == "/" && isEnd) { + state.tokenize = tokenBase; + break; + } + isEnd = (ch == "*"); + } + return ret("comment", "comment"); + } + + function tokenString(quote) { + return function(stream, state) { + var escaped = false, next, end = false; + while((next = stream.next()) != null) { + if (next == quote && !escaped) { + end = true; break; + } + escaped = !escaped && next == "\\"; + } + if (end || !(escaped || multiLineStrings)) + state.tokenize = tokenBase; + return ret("string", "error"); + }; + } + + function tokenBase(stream, state) { + var ch = stream.next(); + + // is a start of string? + if (ch == '"' || ch == "'") + return chain(stream, state, tokenString(ch)); + // is it one of the special chars + else if(/[\[\]{}\(\),;\.]/.test(ch)) + return ret(ch); + // is it a number? + else if(/\d/.test(ch)) { + stream.eatWhile(/[\w\.]/); + return ret("number", "number"); + } + // multi line comment or operator + else if (ch == "/") { + if (stream.eat("*")) { + return chain(stream, state, tokenComment); + } + else { + stream.eatWhile(isOperatorChar); + return ret("operator", "operator"); + } + } + // single line comment or operator + else if (ch=="-") { + if(stream.eat("-")){ + stream.skipToEnd(); + return ret("comment", "comment"); + } + else { + stream.eatWhile(isOperatorChar); + return ret("operator", "operator"); + } + } + // is it an operator