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/clike/index.html | 2 +- imports/codemirror/mode/clojure/clojure.js | 26 +- imports/codemirror/mode/css/css.js | 2 +- imports/codemirror/mode/htmlmixed/htmlmixed.js | 2 +- imports/codemirror/mode/javascript/javascript.js | 6 +- imports/codemirror/mode/less/index.html | 39 +- imports/codemirror/mode/less/less.js | 143 ++++--- imports/codemirror/mode/markdown/index.html | 1 - imports/codemirror/mode/markdown/markdown.js | 89 ++-- imports/codemirror/mode/properties/index.html | 4 +- imports/codemirror/mode/properties/properties.css | 3 - imports/codemirror/mode/properties/properties.js | 28 +- imports/codemirror/mode/scheme/scheme.js | 402 +++++++++--------- imports/codemirror/mode/smarty/index.html | 82 ++++ imports/codemirror/mode/smarty/smarty.js | 148 +++++++ imports/codemirror/mode/stex/stex.js | 17 +- imports/codemirror/mode/stex/test.html | 251 ++++++++++++ imports/codemirror/mode/tiddlywiki/index.html | 69 +--- imports/codemirror/mode/tiddlywiki/tiddlywiki.css | 2 +- imports/codemirror/mode/tiddlywiki/tiddlywiki.js | 72 ++-- imports/codemirror/mode/vbscript/index.html | 42 ++ imports/codemirror/mode/vbscript/vbscript.js | 26 ++ imports/codemirror/mode/xml/xml.js | 3 +- imports/codemirror/mode/xmlpure/index.html | 1 - imports/codemirror/mode/xquery/LICENSE | 20 + imports/codemirror/mode/xquery/index.html | 222 ++++++++++ imports/codemirror/mode/xquery/test/index.html | 27 ++ imports/codemirror/mode/xquery/test/testBase.js | 42 ++ .../mode/xquery/test/testEmptySequenceKeyword.js | 16 + .../codemirror/mode/xquery/test/testMultiAttr.js | 16 + .../codemirror/mode/xquery/test/testNamespaces.js | 91 +++++ .../mode/xquery/test/testProcessingInstructions.js | 16 + imports/codemirror/mode/xquery/test/testQuotes.js | 19 + imports/codemirror/mode/xquery/xquery.js | 448 +++++++++++++++++++++ 34 files changed, 1919 insertions(+), 458 deletions(-) delete mode 100755 imports/codemirror/mode/properties/properties.css create mode 100644 imports/codemirror/mode/smarty/index.html create mode 100644 imports/codemirror/mode/smarty/smarty.js create mode 100644 imports/codemirror/mode/stex/test.html create mode 100644 imports/codemirror/mode/vbscript/index.html create mode 100644 imports/codemirror/mode/vbscript/vbscript.js create mode 100644 imports/codemirror/mode/xquery/LICENSE create mode 100644 imports/codemirror/mode/xquery/index.html create mode 100644 imports/codemirror/mode/xquery/test/index.html create mode 100644 imports/codemirror/mode/xquery/test/testBase.js create mode 100644 imports/codemirror/mode/xquery/test/testEmptySequenceKeyword.js create mode 100644 imports/codemirror/mode/xquery/test/testMultiAttr.js create mode 100644 imports/codemirror/mode/xquery/test/testNamespaces.js create mode 100644 imports/codemirror/mode/xquery/test/testProcessingInstructions.js create mode 100644 imports/codemirror/mode/xquery/test/testQuotes.js create mode 100644 imports/codemirror/mode/xquery/xquery.js (limited to 'imports/codemirror/mode') diff --git a/imports/codemirror/mode/clike/index.html b/imports/codemirror/mode/clike/index.html index 5c327451..64d02f11 100644 --- a/imports/codemirror/mode/clike/index.html +++ b/imports/codemirror/mode/clike/index.html @@ -96,6 +96,6 @@ void* zmq_thread_init(void* zmq_context, int signal_fd) {

MIME types defined: text/x-csrc (C code), text/x-c++src (C++ code), text/x-java (Java - code).

+ code), text/x-csharp (C#).

diff --git a/imports/codemirror/mode/clojure/clojure.js b/imports/codemirror/mode/clojure/clojure.js index cce7ce37..c6836415 100644 --- a/imports/codemirror/mode/clojure/clojure.js +++ b/imports/codemirror/mode/clojure/clojure.js @@ -4,7 +4,7 @@ */ CodeMirror.defineMode("clojure", function (config, mode) { var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", TAG = "tag", - ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword"; + ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD = "keyword"; var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1; function makeKeywords(str) { @@ -14,26 +14,25 @@ CodeMirror.defineMode("clojure", function (config, mode) { } var atoms = makeKeywords("true false nil"); - + var keywords = makeKeywords( - // Control structures - "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle" + + "defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord defproject deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle"); - // Built-ins + var builtins = makeKeywords( "* *1 *2 *3 *agent* *allow-unresolved-vars* *assert *clojure-version* *command-line-args* *compile-files* *compile-path* *e *err* *file* *flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *use-context-classloader* *warn-on-reflection* + - / < <= = == > >= accessor aclone agent agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec decimal? declare definline defmacro defmethod defmulti defn defn- defonce defstruct delay delay? deliver deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall doc dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq eval even? every? extend extend-protocol extend-type extends? extenders false? ffirst file-seq filter find find-doc find-ns find-var first float float-array float? floats flush fn fn? fnext for force format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator hash hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map? mapcat max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? or parents partial partition pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-doc print-dup print-method print-namespace-doc print-simple print-special-doc print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string reify reduce ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends rem remove remove-method remove-ns repeat repeatedly replace replicate require reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-validator! set? short short-array shorts shutdown-agents slurp some sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-form-anchor special-symbol? split-at split-with str stream? string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync syntax-symbol-anchor take take-last take-nth take-while test the-ns time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-dec unchecked-divide unchecked-inc unchecked-multiply unchecked-negate unchecked-remainder unchecked-subtract underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision xml-seq"); var indentKeys = makeKeywords( // Built-ins - "ns fn def defn defmethod bound-fn if if-not case condp when while when-not when-first do future comment doto locking proxy with-open with-precision reify deftype defrecord defprotocol extend extend-protocol extend-type try catch" + + "ns fn def defn defmethod bound-fn if if-not case condp when while when-not when-first do future comment doto locking proxy with-open with-precision reify deftype defrecord defprotocol extend extend-protocol extend-type try catch " + // Binding forms - "let letfn binding loop for doseq dotimes when-let if-let" + + "let letfn binding loop for doseq dotimes when-let if-let " + // Data structures - "defstruct struct-map assoc" + + "defstruct struct-map assoc " + // clojure.test - "testing deftest" + + "testing deftest " + // contrib "handler-case handle dotrace deftrace"); @@ -154,12 +153,11 @@ CodeMirror.defineMode("clojure", function (config, mode) { (;something else, bracket, etc. */ - while ((letter = stream.eat(tests.keyword_char)) != null) { + if (ch == "(") while ((letter = stream.eat(tests.keyword_char)) != null) { keyWord += letter; } if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word - pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); } else { // non-indent word // we continue eating the spaces @@ -182,13 +180,15 @@ CodeMirror.defineMode("clojure", function (config, mode) { } } else if ( ch == ":" ) { stream.eatWhile(tests.lang_keyword); - return TAG; + return ATOM; } else { stream.eatWhile(tests.basic); if (keywords && keywords.propertyIsEnumerable(stream.current())) { + returnType = KEYWORD; + } else if (builtins && builtins.propertyIsEnumerable(stream.current())) { returnType = BUILTIN; - } else if ( atoms && atoms.propertyIsEnumerable(stream.current()) ) { + } else if (atoms && atoms.propertyIsEnumerable(stream.current())) { returnType = ATOM; } else returnType = null; } diff --git a/imports/codemirror/mode/css/css.js b/imports/codemirror/mode/css/css.js index 45170a3d..050e1124 100644 --- a/imports/codemirror/mode/css/css.js +++ b/imports/codemirror/mode/css/css.js @@ -92,7 +92,7 @@ CodeMirror.defineMode("css", function(config) { var style = state.tokenize(stream, state); var context = state.stack[state.stack.length-1]; - if (type == "hash" && context == "rule") style = "atom"; + if (type == "hash" && context != "rule") style = "string-2"; else if (style == "variable") { if (context == "rule") style = "number"; else if (!context || context == "@media{") style = "tag"; diff --git a/imports/codemirror/mode/htmlmixed/htmlmixed.js b/imports/codemirror/mode/htmlmixed/htmlmixed.js index a94dc45f..c66a6583 100644 --- a/imports/codemirror/mode/htmlmixed/htmlmixed.js +++ b/imports/codemirror/mode/htmlmixed/htmlmixed.js @@ -28,7 +28,7 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) { function javascript(stream, state) { if (stream.match(/^<\/\s*script\s*>/i, false)) { state.token = html; - state.curState = null; + state.localState = null; state.mode = "html"; return html(stream, state); } diff --git a/imports/codemirror/mode/javascript/javascript.js b/imports/codemirror/mode/javascript/javascript.js index b9388bc9..462f4863 100644 --- a/imports/codemirror/mode/javascript/javascript.js +++ b/imports/codemirror/mode/javascript/javascript.js @@ -319,8 +319,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { kwAllowed: true, cc: [], lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), - localVars: null, - context: null, + localVars: parserConfig.localVars, + context: parserConfig.localVars && {vars: parserConfig.localVars}, indented: 0 }; }, @@ -334,7 +334,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { if (stream.eatSpace()) return null; var style = state.tokenize(stream, state); if (type == "comment") return style; - state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/); + state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/)); state.kwAllowed = type != '.'; return parseJS(state, style, type, content, stream); }, 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"); diff --git a/imports/codemirror/mode/markdown/index.html b/imports/codemirror/mode/markdown/index.html index 3a60c03f..cae8df44 100644 --- a/imports/codemirror/mode/markdown/index.html +++ b/imports/codemirror/mode/markdown/index.html @@ -6,7 +6,6 @@ - diff --git a/imports/codemirror/mode/markdown/markdown.js b/imports/codemirror/mode/markdown/markdown.js index 800ff0b4..af95753e 100644 --- a/imports/codemirror/mode/markdown/markdown.js +++ b/imports/codemirror/mode/markdown/markdown.js @@ -13,11 +13,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { , strong = 'strong' , emstrong = 'emstrong'; - var hrRE = /^[*-=_]/ - , ulRE = /^[*-+]\s+/ + var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/ + , ulRE = /^[*\-+]\s+/ , olRE = /^[0-9]+\.\s+/ , headerRE = /^(?:\={3,}|-{3,})$/ - , codeRE = /^(k:\t|\s{4,})/ , textRE = /^[^\[*_\\<>`]+/; function switchInline(stream, state, f) { @@ -33,9 +32,18 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { // Blocks + function blankLine(state) { + // Reset EM state + state.em = false; + // Reset STRONG state + state.strong = false; + return null; + } + function blockNormal(stream, state) { var match; - if (stream.match(codeRE)) { + if (state.indentationDiff >= 4) { + state.indentation -= state.indentationDiff; stream.skipToEnd(); return code; } else if (stream.eatSpace()) { @@ -47,11 +55,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { state.quote = true; } else if (stream.peek() === '[') { return switchInline(stream, state, footnoteLink); - } else if (hrRE.test(stream.peek())) { - var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$'); - if (stream.match(re, true)) { - return hr; - } + } else if (stream.match(hrRE, true)) { + return hr; } else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { state.indentation += match[0].length; return list; @@ -72,39 +77,15 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { // Inline function getType(state) { + var styles = []; - // Set defaults - returnValue = ''; - - // Strong / Emphasis - if(state.strong){ - if(state.em){ - returnValue += (returnValue ? ' ' : '') + emstrong; - } else { - returnValue += (returnValue ? ' ' : '') + strong; - } - } else { - if(state.em){ - returnValue += (returnValue ? ' ' : '') + em; - } - } - - // Header - if(state.header){ - returnValue += (returnValue ? ' ' : '') + header; - } - - // Quotes - if(state.quote){ - returnValue += (returnValue ? ' ' : '') + quote; - } - - // Check valud and return - if(!returnValue){ - returnValue = null; - } - return returnValue; + if (state.strong) { styles.push(state.em ? emstrong : strong); } + else if (state.em) { styles.push(em); } + if (state.header) { styles.push(header); } + if (state.quote) { styles.push(quote); } + + return styles.length ? styles.join(' ') : null; } function handleText(stream, state) { @@ -238,36 +219,24 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { token: function(stream, state) { if (stream.sol()) { - // Reset EM state - state.em = false; - // Reset STRONG state - state.strong = false; + if (stream.match(/^\s*$/, true)) { return blankLine(state); } + // Reset state.header state.header = false; // Reset state.quote state.quote = false; state.f = state.block; - var previousIndentation = state.indentation - , currentIndentation = 0; - while (previousIndentation > 0) { - if (stream.eat(' ')) { - previousIndentation--; - currentIndentation++; - } else if (previousIndentation >= 4 && stream.eat('\t')) { - previousIndentation -= 4; - currentIndentation += 4; - } else { - break; - } - } - state.indentation = currentIndentation; - - if (currentIndentation > 0) return null; + var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length; + state.indentationDiff = indentation - state.indentation; + state.indentation = indentation; + if (indentation > 0) { return null; } } return state.f(stream, state); }, + blankLine: blankLine, + getType: getType }; diff --git a/imports/codemirror/mode/properties/index.html b/imports/codemirror/mode/properties/index.html index 3df6a3ae..4f0c269c 100755 --- a/imports/codemirror/mode/properties/index.html +++ b/imports/codemirror/mode/properties/index.html @@ -5,7 +5,6 @@ - @@ -34,7 +33,8 @@ spaces\ in\ keys=Not very common... var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); -

MIME types defined: text/x-properties.

+

MIME types defined: text/x-properties, + text/x-ini.

diff --git a/imports/codemirror/mode/properties/properties.css b/imports/codemirror/mode/properties/properties.css deleted file mode 100755 index d975375c..00000000 --- a/imports/codemirror/mode/properties/properties.css +++ /dev/null @@ -1,3 +0,0 @@ -span.cm-key {color: #00c;} -span.cm-equals {color: #a11;} -span.cm-value {color: #170;} diff --git a/imports/codemirror/mode/properties/properties.js b/imports/codemirror/mode/properties/properties.js index 2529505b..d3a13c76 100755 --- a/imports/codemirror/mode/properties/properties.js +++ b/imports/codemirror/mode/properties/properties.js @@ -1,21 +1,23 @@ CodeMirror.defineMode("properties", function() { return { token: function(stream, state) { - var sol = stream.sol(); + var sol = stream.sol() || state.afterSection; var eol = stream.eol(); + state.afterSection = false; + if (sol) { if (state.nextMultiline) { state.inMultiline = true; state.nextMultiline = false; } else { - state.position = "key"; + state.position = "def"; } } if (eol && ! state.nextMultiline) { state.inMultiline = false; - state.position = "key"; + state.position = "def"; } if (sol) { @@ -24,16 +26,18 @@ CodeMirror.defineMode("properties", function() { var ch = stream.next(); - if (sol && (ch === "#" || ch === "!")) { + if (sol && (ch === "#" || ch === "!" || ch === ";")) { state.position = "comment"; stream.skipToEnd(); return "comment"; - + } else if (sol && ch === "[") { + state.afterSection = true; + stream.skipTo("]"); stream.eat("]"); + return "header"; } else if (ch === "=" || ch === ":") { - state.position = "value"; - return "equals"; - - } else if (ch === "\\" && state.position === "value") { + state.position = "quote"; + return null; + } else if (ch === "\\" && state.position === "quote") { if (stream.next() !== "u") { // u = Unicode sequence \u1234 // Multiline value state.nextMultiline = true; @@ -45,9 +49,10 @@ CodeMirror.defineMode("properties", function() { startState: function() { return { - position : "key", // Current position, "key", "value" or "comment" + position : "def", // Current position, "def", "quote" or "comment" nextMultiline : false, // Is the next line multiline value - inMultiline : false // Is the current line a multiline value + inMultiline : false, // Is the current line a multiline value + afterSection : false // Did we just open a section }; } @@ -55,3 +60,4 @@ CodeMirror.defineMode("properties", function() { }); CodeMirror.defineMIME("text/x-properties", "properties"); +CodeMirror.defineMIME("text/x-ini", "properties"); diff --git a/imports/codemirror/mode/scheme/scheme.js b/imports/codemirror/mode/scheme/scheme.js index 45ae1822..caf78db0 100644 --- a/imports/codemirror/mode/scheme/scheme.js +++ b/imports/codemirror/mode/scheme/scheme.js @@ -1,202 +1,202 @@ -/** - * Author: Koh Zi Han, based on implementation by Koh Zi Chun - */ -CodeMirror.defineMode("scheme", function (config, mode) { - var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", - ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword"; - var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1; - - function makeKeywords(str) { - var obj = {}, words = str.split(" "); - for (var i = 0; i < words.length; ++i) obj[words[i]] = true; - return obj; - } - - var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?"); - var indentKeys = makeKeywords("define let letrec let* lambda"); - - - function stateStack(indent, type, prev) { // represents a state stack object - this.indent = indent; - this.type = type; - this.prev = prev; - } - - function pushStack(state, indent, type) { - state.indentStack = new stateStack(indent, type, state.indentStack); - } - - function popStack(state) { - state.indentStack = state.indentStack.prev; - } - - /** - * Scheme numbers are complicated unfortunately. - * Checks if we're looking at a number, which might be possibly a fraction. - * Also checks that it is not part of a longer identifier. Returns true/false accordingly. - */ - function isNumber(ch, stream){ - if(/[0-9]/.exec(ch) != null){ - stream.eatWhile(/[0-9]/); - stream.eat(/\//); - stream.eatWhile(/[0-9]/); - if (stream.eol() || !(/[a-zA-Z\-\_\/]/.exec(stream.peek()))) return true; - stream.backUp(stream.current().length - 1); // undo all the eating - } - return false; - } - - return { - startState: function () { - return { - indentStack: null, - indentation: 0, - mode: false, - sExprComment: false - }; - }, - - token: function (stream, state) { - if (state.indentStack == null && stream.sol()) { - // update indentation, but only if indentStack is empty - state.indentation = stream.indentation(); - } - - // skip spaces - if (stream.eatSpace()) { - return null; - } - var returnType = null; - - switch(state.mode){ - case "string": // multi-line string parsing mode - var next, escaped = false; - while ((next = stream.next()) != null) { - if (next == "\"" && !escaped) { - - state.mode = false; - break; - } - escaped = !escaped && next == "\\"; - } - returnType = STRING; // continue on in scheme-string mode - break; - case "comment": // comment parsing mode - var next, maybeEnd = false; - while ((next = stream.next()) != null) { - if (next == "#" && maybeEnd) { - - state.mode = false; - break; - } - maybeEnd = (next == "|"); - } - returnType = COMMENT; - break; - case "s-expr-comment": // s-expr commenting mode - state.mode = false; - if(stream.peek() == "(" || stream.peek() == "["){ - // actually start scheme s-expr commenting mode - state.sExprComment = 0; - }else{ - // if not we just comment the entire of the next token - stream.eatWhile(/[^/s]/); // eat non spaces - returnType = COMMENT; - break; - } - default: // default parsing mode - var ch = stream.next(); - - if (ch == "\"") { - state.mode = "string"; - returnType = STRING; - - } else if (ch == "'") { - returnType = ATOM; - } else if (ch == '#') { - if (stream.eat("|")) { // Multi-line comment - state.mode = "comment"; // toggle to comment mode - returnType = COMMENT; - } else if (stream.eat(/[tf]/)) { // #t/#f (atom) - returnType = ATOM; - } else if (stream.eat(';')) { // S-Expr comment - state.mode = "s-expr-comment"; - returnType = COMMENT; - } - - } else if (ch == ";") { // comment - stream.skipToEnd(); // rest of the line is a comment - returnType = COMMENT; - } else if (ch == "-"){ - - if(!isNaN(parseInt(stream.peek()))){ - stream.eatWhile(/[\/0-9]/); - returnType = NUMBER; - }else{ - returnType = null; - } - } else if (isNumber(ch,stream)){ - returnType = NUMBER; - } else if (ch == "(" || ch == "[") { - var keyWord = ''; var indentTemp = stream.column(); - /** - Either - (indent-word .. - (non-indent-word .. - (;something else, bracket, etc. - */ - - while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) { - keyWord += letter; - } - - if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word - - pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); - } else { // non-indent word - // we continue eating the spaces - stream.eatSpace(); - if (stream.eol() || stream.peek() == ";") { - // nothing significant after - // we restart indentation 1 space after - pushStack(state, indentTemp + 1, ch); - } else { - pushStack(state, indentTemp + stream.current().length, ch); // else we match - } - } - stream.backUp(stream.current().length - 1); // undo all the eating - - if(typeof state.sExprComment == "number") state.sExprComment++; - - returnType = BRACKET; - } else if (ch == ")" || ch == "]") { - returnType = BRACKET; - if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) { - popStack(state); - - if(typeof state.sExprComment == "number"){ - if(--state.sExprComment == 0){ - returnType = COMMENT; // final closing bracket - state.sExprComment = false; // turn off s-expr commenting mode - } - } - } - } else { - stream.eatWhile(/[\w\$_\-]/); - - if (keywords && keywords.propertyIsEnumerable(stream.current())) { - returnType = BUILTIN; - }else returnType = null; - } - } - return (typeof state.sExprComment == "number") ? COMMENT : returnType; - }, - - indent: function (state, textAfter) { - if (state.indentStack == null) return state.indentation; - return state.indentStack.indent; - } - }; -}); - +/** + * Author: Koh Zi Han, based on implementation by Koh Zi Chun + */ +CodeMirror.defineMode("scheme", function (config, mode) { + var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", + ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword"; + var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1; + + function makeKeywords(str) { + var obj = {}, words = str.split(" "); + for (var i = 0; i < words.length; ++i) obj[words[i]] = true; + return obj; + } + + var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?"); + var indentKeys = makeKeywords("define let letrec let* lambda"); + + + function stateStack(indent, type, prev) { // represents a state stack object + this.indent = indent; + this.type = type; + this.prev = prev; + } + + function pushStack(state, indent, type) { + state.indentStack = new stateStack(indent, type, state.indentStack); + } + + function popStack(state) { + state.indentStack = state.indentStack.prev; + } + + /** + * Scheme numbers are complicated unfortunately. + * Checks if we're looking at a number, which might be possibly a fraction. + * Also checks that it is not part of a longer identifier. Returns true/false accordingly. + */ + function isNumber(ch, stream){ + if(/[0-9]/.exec(ch) != null){ + stream.eatWhile(/[0-9]/); + stream.eat(/\//); + stream.eatWhile(/[0-9]/); + if (stream.eol() || !(/[a-zA-Z\-\_\/]/.exec(stream.peek()))) return true; + stream.backUp(stream.current().length - 1); // undo all the eating + } + return false; + } + + return { + startState: function () { + return { + indentStack: null, + indentation: 0, + mode: false, + sExprComment: false + }; + }, + + token: function (stream, state) { + if (state.indentStack == null && stream.sol()) { + // update indentation, but only if indentStack is empty + state.indentation = stream.indentation(); + } + + // skip spaces + if (stream.eatSpace()) { + return null; + } + var returnType = null; + + switch(state.mode){ + case "string": // multi-line string parsing mode + var next, escaped = false; + while ((next = stream.next()) != null) { + if (next == "\"" && !escaped) { + + state.mode = false; + break; + } + escaped = !escaped && next == "\\"; + } + returnType = STRING; // continue on in scheme-string mode + break; + case "comment": // comment parsing mode + var next, maybeEnd = false; + while ((next = stream.next()) != null) { + if (next == "#" && maybeEnd) { + + state.mode = false; + break; + } + maybeEnd = (next == "|"); + } + returnType = COMMENT; + break; + case "s-expr-comment": // s-expr commenting mode + state.mode = false; + if(stream.peek() == "(" || stream.peek() == "["){ + // actually start scheme s-expr commenting mode + state.sExprComment = 0; + }else{ + // if not we just comment the entire of the next token + stream.eatWhile(/[^/s]/); // eat non spaces + returnType = COMMENT; + break; + } + default: // default parsing mode + var ch = stream.next(); + + if (ch == "\"") { + state.mode = "string"; + returnType = STRING; + + } else if (ch == "'") { + returnType = ATOM; + } else if (ch == '#') { + if (stream.eat("|")) { // Multi-line comment + state.mode = "comment"; // toggle to comment mode + returnType = COMMENT; + } else if (stream.eat(/[tf]/)) { // #t/#f (atom) + returnType = ATOM; + } else if (stream.eat(';')) { // S-Expr comment + state.mode = "s-expr-comment"; + returnType = COMMENT; + } + + } else if (ch == ";") { // comment + stream.skipToEnd(); // rest of the line is a comment + returnType = COMMENT; + } else if (ch == "-"){ + + if(!isNaN(parseInt(stream.peek()))){ + stream.eatWhile(/[\/0-9]/); + returnType = NUMBER; + }else{ + returnType = null; + } + } else if (isNumber(ch,stream)){ + returnType = NUMBER; + } else if (ch == "(" || ch == "[") { + var keyWord = ''; var indentTemp = stream.column(); + /** + Either + (indent-word .. + (non-indent-word .. + (;something else, bracket, etc. + */ + + while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) { + keyWord += letter; + } + + if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word + + pushStack(state, indentTemp + INDENT_WORD_SKIP, ch); + } else { // non-indent word + // we continue eating the spaces + stream.eatSpace(); + if (stream.eol() || stream.peek() == ";") { + // nothing significant after + // we restart indentation 1 space after + pushStack(state, indentTemp + 1, ch); + } else { + pushStack(state, indentTemp + stream.current().length, ch); // else we match + } + } + stream.backUp(stream.current().length - 1); // undo all the eating + + if(typeof state.sExprComment == "number") state.sExprComment++; + + returnType = BRACKET; + } else if (ch == ")" || ch == "]") { + returnType = BRACKET; + if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) { + popStack(state); + + if(typeof state.sExprComment == "number"){ + if(--state.sExprComment == 0){ + returnType = COMMENT; // final closing bracket + state.sExprComment = false; // turn off s-expr commenting mode + } + } + } + } else { + stream.eatWhile(/[\w\$_\-]/); + + if (keywords && keywords.propertyIsEnumerable(stream.current())) { + returnType = BUILTIN; + }else returnType = null; + } + } + return (typeof state.sExprComment == "number") ? COMMENT : returnType; + }, + + indent: function (state, textAfter) { + if (state.indentStack == null) return state.indentation; + return state.indentStack.indent; + } + }; +}); + CodeMirror.defineMIME("text/x-scheme", "scheme"); \ No newline at end of file diff --git a/imports/codemirror/mode/smarty/index.html b/imports/codemirror/mode/smarty/index.html new file mode 100644 index 00000000..ad4dccf0 --- /dev/null +++ b/imports/codemirror/mode/smarty/index.html @@ -0,0 +1,82 @@ + + + + CodeMirror: Smarty mode + + + + + + + +

CodeMirror: Smarty mode

+ +
+ + + +
+ +
+ + + +

A plain text/Smarty mode which allows for custom delimiter tags (defaults to { and }).

+ +

MIME types defined: text/x-smarty

+ + diff --git a/imports/codemirror/mode/smarty/smarty.js b/imports/codemirror/mode/smarty/smarty.js new file mode 100644 index 00000000..9da7da62 --- /dev/null +++ b/imports/codemirror/mode/smarty/smarty.js @@ -0,0 +1,148 @@ +CodeMirror.defineMode("smarty", function(config, parserConfig) { + var keyFuncs = ["debug", "extends", "function", "include", "literal"]; + var last; + var regs = { + operatorChars: /[+\-*&%=<>!?]/, + validIdentifier: /[a-zA-Z0-9\_]/, + stringChar: /[\'\"]/ + } + var leftDelim = (typeof config.mode.leftDelimiter != 'undefined') ? config.mode.leftDelimiter : "{"; + var rightDelim = (typeof config.mode.rightDelimiter != 'undefined') ? config.mode.rightDelimiter : "}"; + function ret(style, lst) { last = lst; return style; } + + + function tokenizer(stream, state) { + function chain(parser) { + state.tokenize = parser; + return parser(stream, state); + } + + if (stream.match(leftDelim, true)) { + if (stream.eat("*")) { + return chain(inBlock("comment", "*" + rightDelim)); + } + else { + state.tokenize = inSmarty; + return "tag"; + } + } + else { + // I'd like to do an eatWhile() here, but I can't get it to eat only up to the rightDelim string/char + stream.next(); + return null; + } + } + + function inSmarty(stream, state) { + if (stream.match(rightDelim, true)) { + state.tokenize = tokenizer; + return ret("tag", null); + } + + var ch = stream.next(); + if (ch == "$") { + stream.eatWhile(regs.validIdentifier); + return ret("variable-2", "variable"); + } + else if (ch == ".") { + return ret("operator", "property"); + } + else if (regs.stringChar.test(ch)) { + state.tokenize = inAttribute(ch); + return ret("string", "string"); + } + else if (regs.operatorChars.test(ch)) { + stream.eatWhile(regs.operatorChars); + return ret("operator", "operator"); + } + else if (ch == "[" || ch == "]") { + return ret("bracket", "bracket"); + } + else if (/\d/.test(ch)) { + stream.eatWhile(/\d/); + return ret("number", "number"); + } + else { + if (state.last == "variable") { + if (ch == "@") { + stream.eatWhile(regs.validIdentifier); + return ret("property", "property"); + } + else if (ch == "|") { + stream.eatWhile(regs.validIdentifier); + return ret("qualifier", "modifier"); + } + } + else if (state.last == "whitespace") { + stream.eatWhile(regs.validIdentifier); + return ret("attribute", "modifier"); + } + else if (state.last == "property") { + stream.eatWhile(regs.validIdentifier); + return ret("property", null); + } + else if (/\s/.test(ch)) { + last = "whitespace"; + return null; + } + + var str = ""; + if (ch != "/") { + str += ch; + } + var c = ""; + while ((c = stream.eat(regs.validIdentifier))) { + str += c; + } + var i, j; + for (i=0, j=keyFuncs.length; i