codemirror-rails 2.33 → 2.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/lib/codemirror/rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/codemirror.js +359 -453
  3. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +4 -1
  4. data/vendor/assets/javascripts/codemirror/modes/clojure.js +7 -8
  5. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +101 -0
  6. data/vendor/assets/javascripts/codemirror/modes/css.js +336 -62
  7. data/vendor/assets/javascripts/codemirror/modes/gfm.js +6 -1
  8. data/vendor/assets/javascripts/codemirror/modes/haxe.js +0 -3
  9. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +5 -1
  10. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +11 -12
  11. data/vendor/assets/javascripts/codemirror/modes/javascript.js +1 -1
  12. data/vendor/assets/javascripts/codemirror/modes/markdown.js +131 -17
  13. data/vendor/assets/javascripts/codemirror/modes/php.js +4 -6
  14. data/vendor/assets/javascripts/codemirror/modes/shell.js +1 -1
  15. data/vendor/assets/javascripts/codemirror/modes/tiki.js +0 -7
  16. data/vendor/assets/javascripts/codemirror/modes/vb.js +2 -2
  17. data/vendor/assets/javascripts/codemirror/modes/xml.js +0 -8
  18. data/vendor/assets/javascripts/codemirror/utils/closetag.js +35 -35
  19. data/vendor/assets/javascripts/codemirror/utils/formatting.js +147 -253
  20. data/vendor/assets/javascripts/codemirror/utils/multiplex.js +4 -8
  21. data/vendor/assets/javascripts/codemirror/utils/overlay.js +3 -1
  22. data/vendor/assets/javascripts/codemirror/utils/runmode-standalone.js +90 -0
  23. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +1 -1
  24. data/vendor/assets/stylesheets/codemirror.css +2 -2
  25. metadata +14 -12
@@ -96,7 +96,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {
96
96
  },
97
97
 
98
98
  copyState: function(state) {
99
- return {token: state.token, mode: state.mode, mdState: CodeMirror.copyState(mdMode, state.mdState),
99
+ return {token: state.token, mdState: CodeMirror.copyState(mdMode, state.mdState),
100
100
  localMode: state.localMode,
101
101
  localState: state.localMode ? CodeMirror.copyState(state.localMode, state.localState) : null};
102
102
  },
@@ -140,6 +140,11 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) {
140
140
  }
141
141
 
142
142
  return state.token(stream, state);
143
+ },
144
+
145
+ innerMode: function(state) {
146
+ if (state.token == markdown) return {state: state.mdState, mode: mdMode};
147
+ else return {state: state.localState, mode: state.localMode};
143
148
  }
144
149
  };
145
150
  }, "markdown");
@@ -421,9 +421,6 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
421
421
  else if (lexical.align) return lexical.column + (closing ? 0 : 1);
422
422
  else return lexical.indented + (closing ? 0 : indentUnit);
423
423
  },
424
- compareStates: function(state1, state2) {
425
- return (state1.localVars == state2.localVars) && (state1.context == state2.context);
426
- },
427
424
 
428
425
  electricChars: "{}"
429
426
  };
@@ -58,8 +58,12 @@ CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
58
58
  };
59
59
  },
60
60
 
61
+ electricChars: "/{}:",
61
62
 
62
- electricChars: "/{}:"
63
+ innerMode: function(state) {
64
+ if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode};
65
+ else return {state: state.htmlState, mode: htmlMixedMode};
66
+ }
63
67
  };
64
68
  }, "htmlmixed");
65
69
 
@@ -1,4 +1,4 @@
1
- CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
1
+ CodeMirror.defineMode("htmlmixed", function(config) {
2
2
  var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
3
3
  var jsMode = CodeMirror.getMode(config, "javascript");
4
4
  var cssMode = CodeMirror.getMode(config, "css");
@@ -9,27 +9,28 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
9
9
  if (/^script$/i.test(state.htmlState.context.tagName)) {
10
10
  state.token = javascript;
11
11
  state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12
- state.mode = "javascript";
13
12
  }
14
13
  else if (/^style$/i.test(state.htmlState.context.tagName)) {
15
14
  state.token = css;
16
15
  state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17
- state.mode = "css";
18
16
  }
19
17
  }
20
18
  return style;
21
19
  }
22
20
  function maybeBackup(stream, pat, style) {
23
21
  var cur = stream.current();
24
- var close = cur.search(pat);
22
+ var close = cur.search(pat), m;
25
23
  if (close > -1) stream.backUp(cur.length - close);
24
+ else if (m = cur.match(/<\/?$/)) {
25
+ stream.backUp(cur[0].length);
26
+ if (!stream.match(pat, false)) stream.match(cur[0]);
27
+ }
26
28
  return style;
27
29
  }
28
30
  function javascript(stream, state) {
29
31
  if (stream.match(/^<\/\s*script\s*>/i, false)) {
30
32
  state.token = html;
31
33
  state.localState = null;
32
- state.mode = "html";
33
34
  return html(stream, state);
34
35
  }
35
36
  return maybeBackup(stream, /<\/\s*script\s*>/,
@@ -39,7 +40,6 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
39
40
  if (stream.match(/^<\/\s*style\s*>/i, false)) {
40
41
  state.token = html;
41
42
  state.localState = null;
42
- state.mode = "html";
43
43
  return html(stream, state);
44
44
  }
45
45
  return maybeBackup(stream, /<\/\s*style\s*>/,
@@ -72,13 +72,12 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
72
72
  return cssMode.indent(state.localState, textAfter);
73
73
  },
74
74
 
75
- compareStates: function(a, b) {
76
- if (a.mode != b.mode) return false;
77
- if (a.localState) return CodeMirror.Pass;
78
- return htmlMode.compareStates(a.htmlState, b.htmlState);
79
- },
75
+ electricChars: "/{}:",
80
76
 
81
- electricChars: "/{}:"
77
+ innerMode: function(state) {
78
+ var mode = state.token == html ? htmlMode : state.token == javascript ? jsMode : cssMode;
79
+ return {state: state.localState || state.htmlState, mode: mode};
80
+ }
82
81
  };
83
82
  }, "xml", "javascript", "css");
84
83
 
@@ -175,8 +175,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
175
175
 
176
176
  var defaultVars = {name: "this", next: {name: "arguments"}};
177
177
  function pushcontext() {
178
- if (!cx.state.context) cx.state.localVars = defaultVars;
179
178
  cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
179
+ cx.state.localVars = defaultVars;
180
180
  }
181
181
  function popcontext() {
182
182
  cx.state.localVars = cx.state.context.vars;
@@ -2,12 +2,18 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
2
2
 
3
3
  var htmlFound = CodeMirror.mimeModes.hasOwnProperty("text/html");
4
4
  var htmlMode = CodeMirror.getMode(cmCfg, htmlFound ? "text/html" : "text/plain");
5
+
6
+ var codeDepth = 0;
7
+ var prevLineHasContent = false
8
+ , thisLineHasContent = false;
5
9
 
6
10
  var header = 'header'
7
11
  , code = 'comment'
8
12
  , quote = 'quote'
9
13
  , list = 'string'
10
14
  , hr = 'hr'
15
+ , linkinline = 'link'
16
+ , linkemail = 'link'
11
17
  , linktext = 'link'
12
18
  , linkhref = 'string'
13
19
  , em = 'em'
@@ -17,8 +23,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
17
23
  var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/
18
24
  , ulRE = /^[*\-+]\s+/
19
25
  , olRE = /^[0-9]+\.\s+/
20
- , headerRE = /^(?:\={3,}|-{3,})$/
21
- , textRE = /^[^\[*_\\<>`]+/;
26
+ , headerRE = /^(?:\={1,}|-{1,})$/
27
+ , textRE = /^[^\[*_\\<>` "'(]+/;
22
28
 
23
29
  function switchInline(stream, state, f) {
24
30
  state.f = state.inline = f;
@@ -34,6 +40,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
34
40
  // Blocks
35
41
 
36
42
  function blankLine(state) {
43
+ // Reset linkTitle state
44
+ state.linkTitle = false;
45
+ // Reset CODE state
46
+ state.code = false;
37
47
  // Reset EM state
38
48
  state.em = false;
39
49
  // Reset STRONG state
@@ -49,13 +59,23 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
49
59
 
50
60
  function blockNormal(stream, state) {
51
61
  var match;
62
+
63
+ if (state.list !== false && state.indentationDiff >= 0) { // Continued list
64
+ if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block
65
+ state.indentation -= state.indentationDiff;
66
+ }
67
+ state.list = null;
68
+ } else { // No longer a list
69
+ state.list = false;
70
+ }
71
+
52
72
  if (state.indentationDiff >= 4) {
53
- state.indentation -= state.indentationDiff;
73
+ state.indentation -= 4;
54
74
  stream.skipToEnd();
55
75
  return code;
56
76
  } else if (stream.eatSpace()) {
57
77
  return null;
58
- } else if (stream.peek() === '#' || stream.match(headerRE)) {
78
+ } else if (stream.peek() === '#' || (prevLineHasContent && stream.match(headerRE)) ) {
59
79
  state.header = true;
60
80
  } else if (stream.eat('>')) {
61
81
  state.indentation++;
@@ -65,8 +85,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
65
85
  } else if (stream.match(hrRE, true)) {
66
86
  return hr;
67
87
  } else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) {
68
- state.indentation += match[0].length;
69
- return list;
88
+ state.indentation += 4;
89
+ state.list = true;
70
90
  }
71
91
 
72
92
  return switchInline(stream, state, state.inline);
@@ -94,8 +114,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
94
114
  if (state.strong) { styles.push(state.em ? emstrong : strong); }
95
115
  else if (state.em) { styles.push(em); }
96
116
 
117
+ if (state.code) { styles.push(code); }
118
+
97
119
  if (state.header) { styles.push(header); }
98
120
  if (state.quote) { styles.push(quote); }
121
+ if (state.list !== false) { styles.push(list); }
99
122
 
100
123
  return styles.length ? styles.join(' ') : null;
101
124
  }
@@ -112,18 +135,64 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
112
135
  if (typeof style !== 'undefined')
113
136
  return style;
114
137
 
138
+ if (state.list) { // List marker (*, +, -, 1., etc)
139
+ state.list = null;
140
+ return list;
141
+ }
142
+
115
143
  var ch = stream.next();
116
144
 
117
145
  if (ch === '\\') {
118
146
  stream.next();
119
147
  return getType(state);
120
148
  }
149
+
150
+ // Matches link titles present on next line
151
+ if (state.linkTitle) {
152
+ state.linkTitle = false;
153
+ var matchCh = ch;
154
+ if (ch === '(') {
155
+ matchCh = ')';
156
+ }
157
+ matchCh = (matchCh+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
158
+ var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
159
+ if (stream.match(new RegExp(regex), true)) {
160
+ return linkhref;
161
+ }
162
+ }
163
+
121
164
  if (ch === '`') {
122
- return switchInline(stream, state, inlineElement(code, '`'));
165
+ var t = getType(state);
166
+ var before = stream.pos;
167
+ stream.eatWhile('`');
168
+ var difference = 1 + stream.pos - before;
169
+ if (!state.code) {
170
+ codeDepth = difference;
171
+ state.code = true;
172
+ return getType(state);
173
+ } else {
174
+ if (difference === codeDepth) { // Must be exact
175
+ state.code = false;
176
+ return t;
177
+ }
178
+ return getType(state);
179
+ }
180
+ } else if (state.code) {
181
+ return getType(state);
123
182
  }
124
- if (ch === '[' && stream.match(/.*\](?:\(|\[)/, false)) {
183
+
184
+ if (ch === '[' && stream.match(/.*\] ?(?:\(|\[)/, false)) {
125
185
  return switchInline(stream, state, linkText);
126
186
  }
187
+
188
+ if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, true)) {
189
+ return switchInline(stream, state, inlineElement(linkinline, '>'));
190
+ }
191
+
192
+ if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, true)) {
193
+ return switchInline(stream, state, inlineElement(linkemail, '>'));
194
+ }
195
+
127
196
  if (ch === '<' && stream.match(/^\w/, false)) {
128
197
  var md_inside = false;
129
198
  if (stream.string.indexOf(">")!=-1) {
@@ -143,10 +212,27 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
143
212
 
144
213
  var t = getType(state);
145
214
  if (ch === '*' || ch === '_') {
146
- if (stream.eat(ch)) {
147
- return (state.strong = !state.strong) ? getType(state) : t;
215
+ if (state.strong === ch && stream.eat(ch)) { // Remove STRONG
216
+ state.strong = false;
217
+ return t;
218
+ } else if (!state.strong && stream.eat(ch)) { // Add STRONG
219
+ state.strong = ch;
220
+ return getType(state);
221
+ } else if (state.em === ch) { // Remove EM
222
+ state.em = false;
223
+ return t;
224
+ } else if (!state.em) { // Add EM
225
+ state.em = ch;
226
+ return getType(state);
227
+ }
228
+ } else if (ch === ' ') {
229
+ if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
230
+ if (stream.peek() === ' ') { // Surrounded by spaces, ignore
231
+ return getType(state);
232
+ } else { // Not surrounded by spaces, back up pointer
233
+ stream.backUp(1);
234
+ }
148
235
  }
149
- return (state.em = !state.em) ? getType(state) : t;
150
236
  }
151
237
 
152
238
  return getType(state);
@@ -165,7 +251,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
165
251
  }
166
252
 
167
253
  function linkHref(stream, state) {
168
- stream.eatSpace();
254
+ // Check if space, and return NULL if so (to avoid marking the space)
255
+ if(stream.eatSpace()){
256
+ return null;
257
+ }
169
258
  var ch = stream.next();
170
259
  if (ch === '(' || ch === '[') {
171
260
  return switchInline(stream, state, inlineElement(linkhref, ch === '(' ? ')' : ']'));
@@ -182,17 +271,29 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
182
271
  }
183
272
 
184
273
  function footnoteUrl(stream, state) {
185
- stream.eatSpace();
274
+ // Check if space, and return NULL if so (to avoid marking the space)
275
+ if(stream.eatSpace()){
276
+ return null;
277
+ }
278
+ // Match URL
186
279
  stream.match(/^[^\s]+/, true);
280
+ // Check for link title
281
+ if (stream.peek() === undefined) { // End of line, set flag to check next line
282
+ state.linkTitle = true;
283
+ } else { // More content on line, check if link title
284
+ stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
285
+ }
187
286
  state.f = state.inline = inlineNormal;
188
287
  return linkhref;
189
288
  }
190
289
 
191
290
  function inlineRE(endChar) {
192
291
  if (!inlineRE[endChar]) {
193
- // match any not-escaped-non-endChar and any escaped char
194
- // then match endChar or eol
195
- inlineRE[endChar] = new RegExp('^(?:[^\\\\\\' + endChar + ']|\\\\.)*(?:\\' + endChar + '|$)');
292
+ // Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741)
293
+ endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
294
+ // Match any non-endChar, escaped character, as well as the closing
295
+ // endChar.
296
+ inlineRE[endChar] = new RegExp('^(?:[^\\\\]+?|\\\\.)*?(' + endChar + ')');
196
297
  }
197
298
  return inlineRE[endChar];
198
299
  }
@@ -217,9 +318,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
217
318
 
218
319
  inline: inlineNormal,
219
320
  text: handleText,
321
+ linkTitle: false,
220
322
  em: false,
221
323
  strong: false,
222
324
  header: false,
325
+ list: false,
223
326
  quote: false
224
327
  };
225
328
  },
@@ -234,9 +337,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
234
337
 
235
338
  inline: s.inline,
236
339
  text: s.text,
340
+ linkTitle: s.linkTitle,
237
341
  em: s.em,
238
342
  strong: s.strong,
239
343
  header: s.header,
344
+ list: s.list,
240
345
  quote: s.quote,
241
346
  md_inside: s.md_inside
242
347
  };
@@ -244,7 +349,16 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
244
349
 
245
350
  token: function(stream, state) {
246
351
  if (stream.sol()) {
247
- if (stream.match(/^\s*$/, true)) { return blankLine(state); }
352
+ if (stream.match(/^\s*$/, true)) {
353
+ prevLineHasContent = false;
354
+ return blankLine(state);
355
+ } else {
356
+ if(thisLineHasContent){
357
+ prevLineHasContent = true;
358
+ thisLineHasContent = false;
359
+ }
360
+ thisLineHasContent = true;
361
+ }
248
362
 
249
363
  // Reset state.header
250
364
  state.header = false;
@@ -56,14 +56,13 @@
56
56
  var phpMode = CodeMirror.getMode(config, phpConfig);
57
57
 
58
58
  function dispatch(stream, state) { // TODO open PHP inside text/css
59
- var isPHP = state.mode == "php";
59
+ var isPHP = state.curMode == phpMode;
60
60
  if (stream.sol() && state.pending != '"') state.pending = null;
61
61
  if (state.curMode == htmlMode) {
62
62
  if (stream.match(/^<\?\w*/)) {
63
63
  state.curMode = phpMode;
64
64
  state.curState = state.php;
65
65
  state.curClose = "?>";
66
- state.mode = "php";
67
66
  return "meta";
68
67
  }
69
68
  if (state.pending == '"') {
@@ -86,13 +85,11 @@
86
85
  state.curMode = jsMode;
87
86
  state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
88
87
  state.curClose = /^<\/\s*script\s*>/i;
89
- state.mode = "javascript";
90
88
  }
91
89
  else if (/^style$/i.test(state.curState.context.tagName)) {
92
90
  state.curMode = cssMode;
93
91
  state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
94
92
  state.curClose = /^<\/\s*style\s*>/i;
95
- state.mode = "css";
96
93
  }
97
94
  }
98
95
  return style;
@@ -101,7 +98,6 @@
101
98
  state.curMode = htmlMode;
102
99
  state.curState = state.html;
103
100
  state.curClose = null;
104
- state.mode = "html";
105
101
  if (isPHP) return "meta";
106
102
  else return dispatch(stream, state);
107
103
  } else {
@@ -141,7 +137,9 @@
141
137
  return state.curMode.indent(state.curState, textAfter);
142
138
  },
143
139
 
144
- electricChars: "/{}:"
140
+ electricChars: "/{}:",
141
+
142
+ innerMode: function(state) { return {state: state.curState, mode: state.curMode}; }
145
143
  };
146
144
  }, "xml", "clike", "javascript", "css");
147
145
  CodeMirror.defineMIME("application/x-httpd-php", "php");
@@ -60,7 +60,7 @@ CodeMirror.defineMode('shell', function(config) {
60
60
  stream.eatWhile(/\w/);
61
61
  var cur = stream.current();
62
62
  if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
63
- return words[cur] || null;
63
+ return words.hasOwnProperty(cur) ? words[cur] : null;
64
64
  }
65
65
 
66
66
  function tokenString(quote) {