codemirror-rails 5.9 → 5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,9 +12,8 @@
12
12
  "use strict";
13
13
 
14
14
  CodeMirror.defineMode("css", function(config, parserConfig) {
15
- var provided = parserConfig;
15
+ var inline = parserConfig.inline
16
16
  if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
17
- parserConfig.inline = provided.inline;
18
17
 
19
18
  var indentUnit = config.indentUnit,
20
19
  tokenHooks = parserConfig.tokenHooks,
@@ -368,9 +367,9 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
368
367
  return {
369
368
  startState: function(base) {
370
369
  return {tokenize: null,
371
- state: parserConfig.inline ? "block" : "top",
370
+ state: inline ? "block" : "top",
372
371
  stateArg: null,
373
- context: new Context(parserConfig.inline ? "block" : "top", base || 0, null)};
372
+ context: new Context(inline ? "block" : "top", base || 0, null)};
374
373
  },
375
374
 
376
375
  token: function(stream, state) {
@@ -35,11 +35,13 @@
35
35
  "truncatechars_html", "truncatewords", "truncatewords_html",
36
36
  "unordered_list", "upper", "urlencode", "urlize",
37
37
  "urlizetrunc", "wordcount", "wordwrap", "yesno"],
38
- operators = ["==", "!=", "<", ">", "<=", ">=", "in", "not", "or", "and"];
38
+ operators = ["==", "!=", "<", ">", "<=", ">="],
39
+ wordOperators = ["in", "not", "or", "and"];
39
40
 
40
41
  keywords = new RegExp("^\\b(" + keywords.join("|") + ")\\b");
41
42
  filters = new RegExp("^\\b(" + filters.join("|") + ")\\b");
42
43
  operators = new RegExp("^\\b(" + operators.join("|") + ")\\b");
44
+ wordOperators = new RegExp("^\\b(" + wordOperators.join("|") + ")\\b");
43
45
 
44
46
  // We have to return "null" instead of null, in order to avoid string
45
47
  // styling as the default, when using Django templates inside HTML
@@ -270,6 +272,11 @@
270
272
  return "operator";
271
273
  }
272
274
 
275
+ // Attempt to match a word operator
276
+ if (stream.match(wordOperators)) {
277
+ return "keyword";
278
+ }
279
+
273
280
  // Attempt to match a keyword
274
281
  var keywordMatch = stream.match(keywords);
275
282
  if (keywordMatch) {
@@ -3,15 +3,15 @@
3
3
 
4
4
  (function(mod) {
5
5
  if (typeof exports == "object" && typeof module == "object") // CommonJS
6
- mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
6
+ mod(require("../../lib/codemirror"), require("../../addon/mode/simple"), require("../../addon/mode/multiplex"));
7
7
  else if (typeof define == "function" && define.amd) // AMD
8
- define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
8
+ define(["../../lib/codemirror", "../../addon/mode/simple", "../../addon/mode/multiplex"], mod);
9
9
  else // Plain browser env
10
10
  mod(CodeMirror);
11
11
  })(function(CodeMirror) {
12
12
  "use strict";
13
13
 
14
- CodeMirror.defineSimpleMode("handlebars", {
14
+ CodeMirror.defineSimpleMode("handlebars-tags", {
15
15
  start: [
16
16
  { regex: /\{\{!--/, push: "dash_comment", token: "comment" },
17
17
  { regex: /\{\{!/, push: "comment", token: "comment" },
@@ -49,5 +49,14 @@
49
49
  ]
50
50
  });
51
51
 
52
+ CodeMirror.defineMode("handlebars", function(config, parserConfig) {
53
+ var handlebars = CodeMirror.getMode(config, "handlebars-tags");
54
+ if (!parserConfig || !parserConfig.base) return handlebars;
55
+ return CodeMirror.multiplexingMode(
56
+ CodeMirror.getMode(config, parserConfig.base),
57
+ {open: "{{", close: "}}", mode: handlebars, parseDelimiters: true}
58
+ );
59
+ });
60
+
52
61
  CodeMirror.defineMIME("text/x-handlebars-template", "handlebars");
53
62
  });
@@ -45,15 +45,20 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
45
45
  var type = {type: "variable", style: "variable-3"};
46
46
  var tsKeywords = {
47
47
  // object-like things
48
- "interface": kw("interface"),
49
- "extends": kw("extends"),
50
- "constructor": kw("constructor"),
48
+ "interface": kw("class"),
49
+ "implements": C,
50
+ "namespace": C,
51
+ "module": kw("module"),
52
+ "enum": kw("module"),
51
53
 
52
54
  // scope modifiers
53
- "public": kw("public"),
54
- "private": kw("private"),
55
- "protected": kw("protected"),
56
- "static": kw("static"),
55
+ "public": kw("modifier"),
56
+ "private": kw("modifier"),
57
+ "protected": kw("modifier"),
58
+ "abstract": kw("modifier"),
59
+
60
+ // operators
61
+ "as": operator,
57
62
 
58
63
  // types
59
64
  "string": type, "number": type, "boolean": type, "any": type
@@ -121,7 +126,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
121
126
  } else if (stream.eat("/")) {
122
127
  stream.skipToEnd();
123
128
  return ret("comment", "comment");
124
- } else if (/^(?:operator|sof|keyword c|case|new|[\[{}\(,;:])$/.test(state.lastType)) {
129
+ } else if (/^(?:operator|sof|keyword c|case|new|[\[{}\(,;:])$/.test(state.lastType) ||
130
+ (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - 1)))) {
125
131
  readRegexp(stream);
126
132
  stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
127
133
  return ret("regexp", "string-2");
@@ -355,6 +361,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
355
361
  if (type == "class") return cont(pushlex("form"), className, poplex);
356
362
  if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
357
363
  if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
364
+ if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
358
365
  return pass(pushlex("stat"), expression, expect(";"), poplex);
359
366
  }
360
367
  function expression(type) {
@@ -459,6 +466,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
459
466
  return cont(afterprop);
460
467
  } else if (type == "jsonld-keyword") {
461
468
  return cont(afterprop);
469
+ } else if (type == "modifier") {
470
+ return cont(objprop)
462
471
  } else if (type == "[") {
463
472
  return cont(expression, expect("]"), afterprop);
464
473
  } else if (type == "spread") {
@@ -511,6 +520,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
511
520
  return pass(pattern, maybetype, maybeAssign, vardefCont);
512
521
  }
513
522
  function pattern(type, value) {
523
+ if (type == "modifier") return cont(pattern)
514
524
  if (type == "variable") { register(value); return cont(); }
515
525
  if (type == "spread") return cont(pattern);
516
526
  if (type == "[") return contCommasep(pattern, "]");
@@ -620,7 +620,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
620
620
  }
621
621
 
622
622
  function footnoteLink(stream, state) {
623
- if (stream.match(/^[^\]]*\]:/, false)) {
623
+ if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
624
624
  state.f = footnoteLinkInside;
625
625
  stream.next(); // Consume [
626
626
  if (modeCfg.highlightFormatting) state.formatting = "link";
@@ -639,7 +639,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
639
639
  return returnType;
640
640
  }
641
641
 
642
- stream.match(/^[^\]]+/, true);
642
+ stream.match(/^([^\]\\]|\\.)+/, true);
643
643
 
644
644
  return tokenTypes.linkText;
645
645
  }
@@ -69,11 +69,11 @@
69
69
  CodeMirror.defineMIME("text/x-msgenny", {name: "mscgen", language: "msgenny"});
70
70
 
71
71
  function wordRegexpBoundary(pWords) {
72
- return new RegExp("\\b((" + pWords.join(")|(") + "))\\b", "i");
72
+ return new RegExp("\\b(" + pWords.join("|") + ")\\b", "i");
73
73
  }
74
74
 
75
75
  function wordRegexp(pWords) {
76
- return new RegExp("((" + pWords.join(")|(") + "))", "i");
76
+ return new RegExp("(" + pWords.join("|") + ")", "i");
77
77
  }
78
78
 
79
79
  function startStateFn() {
@@ -165,7 +165,9 @@ CodeMirror.defineMode("sparql", function(config) {
165
165
  return context.col + (closing ? 0 : 1);
166
166
  else
167
167
  return context.indent + (closing ? 0 : indentUnit);
168
- }
168
+ },
169
+
170
+ lineComment: "#"
169
171
  };
170
172
  });
171
173
 
@@ -13,189 +13,149 @@
13
13
  })(function(CodeMirror) {
14
14
  "use strict"
15
15
 
16
- function trim(str) { return /^\s*(.*?)\s*$/.exec(str)[1] }
16
+ function wordSet(words) {
17
+ var set = {}
18
+ for (var i = 0; i < words.length; i++) set[words[i]] = true
19
+ return set
20
+ }
21
+
22
+ var keywords = wordSet(["var","let","class","deinit","enum","extension","func","import","init","protocol",
23
+ "static","struct","subscript","typealias","as","dynamicType","is","new","super",
24
+ "self","Self","Type","__COLUMN__","__FILE__","__FUNCTION__","__LINE__","break","case",
25
+ "continue","default","do","else","fallthrough","if","in","for","return","switch",
26
+ "where","while","associativity","didSet","get","infix","inout","left","mutating",
27
+ "none","nonmutating","operator","override","postfix","precedence","prefix","right",
28
+ "set","unowned","weak","willSet"])
29
+ var definingKeywords = wordSet(["var","let","class","enum","extension","func","import","protocol","struct",
30
+ "typealias","dynamicType","for"])
31
+ var atoms = wordSet(["Infinity","NaN","undefined","null","true","false","on","off","yes","no","nil","null",
32
+ "this","super"])
33
+ var types = wordSet(["String","bool","int","string","double","Double","Int","Float","float","public",
34
+ "private","extension"])
35
+ var operators = "+-/*%=|&<>#"
36
+ var punc = ";,.(){}[]"
37
+ var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/
38
+ var number = /^-?(?:(?:[\d_]+\.[_\d]*|\.[_\d]+|0o[0-7_\.]+|0b[01_\.]+)(?:e-?[\d_]+)?|0x[\d_a-f\.]+(?:p-?[\d_]+)?)/i
39
+ var identifier = /^[_A-Za-z$][_A-Za-z$0-9]*/
40
+ var property = /^[@\.][_A-Za-z$][_A-Za-z$0-9]*/
41
+ var regexp = /^\/(?!\s)(?:\/\/)?(?:\\.|[^\/])+\//
17
42
 
18
- var separators = [" ","\\\+","\\\-","\\\(","\\\)","\\\*","/",":","\\\?","\\\<","\\\>"," ","\\\."]
19
- var tokens = new RegExp(separators.join("|"),"g")
43
+ function tokenBase(stream, state, prev) {
44
+ if (stream.eatSpace()) return null
20
45
 
21
- function getWord(string, pos) {
22
- var index = -1, count = 1
23
- var words = string.split(tokens)
24
- for (var i = 0; i < words.length; i++) {
25
- for(var j = 1; j <= words[i].length; j++) {
26
- if (count==pos) index = i
27
- count++
46
+ var ch = stream.peek()
47
+ if (ch == "/") {
48
+ if (stream.match("//")) {
49
+ stream.skipToEnd()
50
+ return "comment"
28
51
  }
29
- count++
52
+ if (stream.match("/*")) {
53
+ state.tokenize.push(tokenComment)
54
+ return tokenComment(stream, state)
55
+ }
56
+ if (stream.match(regexp)) return "string-2"
30
57
  }
31
- var ret = ["", ""]
32
- if (pos == 0) {
33
- ret[1] = words[0]
34
- ret[0] = null
35
- } else {
36
- ret[1] = words[index]
37
- ret[0] = words[index-1]
58
+ if (operators.indexOf(ch) > -1) {
59
+ stream.next()
60
+ return "operator"
61
+ }
62
+ if (punc.indexOf(ch) > -1) {
63
+ stream.match(delimiters)
64
+ return "punctuation"
65
+ }
66
+ if (ch == '"' || ch == "'") {
67
+ stream.next()
68
+ var tokenize = tokenString(ch)
69
+ state.tokenize.push(tokenize)
70
+ return tokenize(stream, state)
38
71
  }
39
- return ret
40
- }
41
72
 
42
- CodeMirror.defineMode("swift", function() {
43
- var keywords=["var","let","class","deinit","enum","extension","func","import","init","let","protocol","static","struct","subscript","typealias","var","as","dynamicType","is","new","super","self","Self","Type","__COLUMN__","__FILE__","__FUNCTION__","__LINE__","break","case","continue","default","do","else","fallthrough","if","in","for","return","switch","where","while","associativity","didSet","get","infix","inout","left","mutating","none","nonmutating","operator","override","postfix","precedence","prefix","right","set","unowned","unowned(safe)","unowned(unsafe)","weak","willSet"]
44
- var commonConstants=["Infinity","NaN","undefined","null","true","false","on","off","yes","no","nil","null","this","super"]
45
- var types=["String","bool","int","string","double","Double","Int","Float","float","public","private","extension"]
46
- var numbers=["0","1","2","3","4","5","6","7","8","9"]
47
- var operators=["+","-","/","*","%","=","|","&","<",">"]
48
- var punc=[";",",",".","(",")","{","}","[","]"]
49
- var delimiters=/^(?:[()\[\]{},:`=;]|\.\.?\.?)/
50
- var identifiers=/^[_A-Za-z$][_A-Za-z$0-9]*/
51
- var properties=/^(@|this\.)[_A-Za-z$][_A-Za-z$0-9]*/
52
- var regexPrefixes=/^(\/{3}|\/)/
73
+ if (stream.match(number)) return "number"
74
+ if (stream.match(property)) return "property"
53
75
 
54
- return {
55
- startState: function() {
56
- return {
57
- prev: false,
58
- string: false,
59
- escape: false,
60
- inner: false,
61
- comment: false,
62
- num_left: 0,
63
- num_right: 0,
64
- doubleString: false,
65
- singleString: false
76
+ if (stream.match(identifier)) {
77
+ var ident = stream.current()
78
+ if (keywords.hasOwnProperty(ident)) {
79
+ if (definingKeywords.hasOwnProperty(ident))
80
+ state.prev = "define"
81
+ return "keyword"
82
+ }
83
+ if (types.hasOwnProperty(ident)) return "variable-2"
84
+ if (atoms.hasOwnProperty(ident)) return "atom"
85
+ if (prev == "define") return "def"
86
+ return "variable"
87
+ }
88
+
89
+ stream.next()
90
+ return null
91
+ }
92
+
93
+ function tokenUntilClosingParen() {
94
+ var depth = 0
95
+ return function(stream, state, prev) {
96
+ var inner = tokenBase(stream, state, prev)
97
+ if (inner == "punctuation") {
98
+ if (stream.current() == "(") ++depth
99
+ else if (stream.current() == ")") {
100
+ if (depth == 0) {
101
+ stream.backUp(1)
102
+ state.tokenize.pop()
103
+ return state.tokenize[state.tokenize.length - 1](stream, state)
104
+ }
105
+ else --depth
66
106
  }
67
- },
68
- token: function(stream, state) {
69
- if (stream.eatSpace()) return null
107
+ }
108
+ return inner
109
+ }
110
+ }
70
111
 
71
- var ch = stream.next()
72
- if (state.string) {
73
- if (state.escape) {
74
- state.escape = false
112
+ function tokenString(quote) {
113
+ return function(stream, state) {
114
+ var ch, escaped = false
115
+ while (ch = stream.next()) {
116
+ if (escaped) {
117
+ if (ch == "(") {
118
+ state.tokenize.push(tokenUntilClosingParen())
75
119
  return "string"
76
- } else {
77
- if ((ch == "\"" && (state.doubleString && !state.singleString) ||
78
- (ch == "'" && (!state.doubleString && state.singleString))) &&
79
- !state.escape) {
80
- state.string = false
81
- state.doubleString = false
82
- state.singleString = false
83
- return "string"
84
- } else if (ch == "\\" && stream.peek() == "(") {
85
- state.inner = true
86
- state.string = false
87
- return "keyword"
88
- } else if (ch == "\\" && stream.peek() != "(") {
89
- state.escape = true
90
- state.string = true
91
- return "string"
92
- } else {
93
- return "string"
94
- }
95
- }
96
- } else if (state.comment) {
97
- if (ch == "*" && stream.peek() == "/") {
98
- state.prev = "*"
99
- return "comment"
100
- } else if (ch == "/" && state.prev == "*") {
101
- state.prev = false
102
- state.comment = false
103
- return "comment"
104
120
  }
105
- return "comment"
121
+ escaped = false
122
+ } else if (ch == quote) {
123
+ break
106
124
  } else {
107
- if (ch == "/") {
108
- if (stream.peek() == "/") {
109
- stream.skipToEnd()
110
- return "comment"
111
- }
112
- if (stream.peek() == "*") {
113
- state.comment = true
114
- return "comment"
115
- }
116
- }
117
- if (ch == "(" && state.inner) {
118
- state.num_left++
119
- return null
120
- }
121
- if (ch == ")" && state.inner) {
122
- state.num_right++
123
- if (state.num_left == state.num_right) {
124
- state.inner=false
125
- state.string=true
126
- }
127
- return null
128
- }
129
-
130
- var ret = getWord(stream.string, stream.pos)
131
- var the_word = ret[1]
132
- var prev_word = ret[0]
133
-
134
- if (operators.indexOf(ch + "") > -1) return "operator"
135
- if (punc.indexOf(ch) > -1) return "punctuation"
136
-
137
- if (typeof the_word != "undefined") {
138
- the_word = trim(the_word)
139
- if (typeof prev_word != "undefined") prev_word = trim(prev_word)
140
- if (the_word.charAt(0) == "#") return null
141
-
142
- if (types.indexOf(the_word) > -1) return "def"
143
- if (commonConstants.indexOf(the_word) > -1) return "atom"
144
- if (numbers.indexOf(the_word) > -1) return "number"
125
+ escaped = ch == "\\"
126
+ }
127
+ }
128
+ state.tokenize.pop()
129
+ return "string"
130
+ }
131
+ }
145
132
 
146
- if ((numbers.indexOf(the_word.charAt(0) + "") > -1 ||
147
- operators.indexOf(the_word.charAt(0) + "") > -1) &&
148
- numbers.indexOf(ch) > -1) {
149
- return "number"
150
- }
133
+ function tokenComment(stream, state) {
134
+ stream.match(/^(?:[^*]|\*(?!\/))*/)
135
+ if (stream.match("*/")) state.tokenize.pop()
136
+ return "comment"
137
+ }
151
138
 
152
- if (keywords.indexOf(the_word) > -1 ||
153
- keywords.indexOf(the_word.split(tokens)[0]) > -1)
154
- return "keyword"
155
- if (keywords.indexOf(prev_word) > -1) return "def"
156
- }
157
- if (ch == '"' && !state.doubleString) {
158
- state.string = true
159
- state.doubleString = true
160
- return "string"
161
- }
162
- if (ch == "'" && !state.singleString) {
163
- state.string = true
164
- state.singleString = true
165
- return "string"
166
- }
167
- if (ch == "(" && state.inner)
168
- state.num_left++
169
- if (ch == ")" && state.inner) {
170
- state.num_right++
171
- if (state.num_left == state.num_right) {
172
- state.inner = false
173
- state.string = true
174
- }
175
- return null
176
- }
177
- if (stream.match(/^-?[0-9\.]/, false)) {
178
- if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i) ||
179
- stream.match(/^-?\d+\.\d*/) ||
180
- stream.match(/^-?\.\d+/)) {
181
- if (stream.peek() == ".") stream.backUp(1)
182
- return "number"
183
- }
184
- if (stream.match(/^-?0x[0-9a-f]+/i) ||
185
- stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/) ||
186
- stream.match(/^-?0(?![\dx])/i))
187
- return "number"
188
- }
189
- if (stream.match(regexPrefixes)) {
190
- if (stream.current()!="/" || stream.match(/^.*\//,false)) return "string"
191
- else stream.backUp(1)
192
- }
193
- if (stream.match(delimiters)) return "punctuation"
194
- if (stream.match(identifiers)) return "variable"
195
- if (stream.match(properties)) return "property"
196
- return "variable"
139
+ CodeMirror.defineMode("swift", function() {
140
+ return {
141
+ startState: function() {
142
+ return {
143
+ prev: null,
144
+ tokenize: []
197
145
  }
198
- }
146
+ },
147
+ token: function(stream, state) {
148
+ var prev = state.prev
149
+ state.prev = null
150
+ var tokenize = state.tokenize[state.tokenize.length - 1] || tokenBase
151
+ var style = tokenize(stream, state, prev)
152
+ if (!style || style == "comment") state.prev = prev
153
+ else if (!state.prev) state.prev = style
154
+ return style
155
+ },
156
+ lineComment: "//",
157
+ blockCommentStart: "/*",
158
+ blockCommentEnd: "*/"
199
159
  }
200
160
  })
201
161