codemirror-rails 3.02 → 3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/LICENSE +1 -1
  4. data/codemirror-rails.gemspec +1 -0
  5. data/doc/CodeMirror-LICENSE +5 -1
  6. data/lib/codemirror/rails/version.rb +2 -2
  7. data/vendor/assets/javascripts/codemirror/{utils → addons/dialog}/dialog.js +4 -0
  8. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +54 -0
  9. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +54 -0
  10. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/closetag.js +9 -8
  11. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/continuecomment.js +12 -4
  12. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -0
  13. data/vendor/assets/javascripts/codemirror/{utils → addons/edit}/matchbrackets.js +30 -11
  14. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +31 -0
  15. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +32 -0
  16. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +11 -0
  17. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +64 -0
  18. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +582 -0
  19. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/javascript-hint.js +15 -11
  20. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/pig-hint.js +19 -19
  21. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/python-hint.js +2 -2
  22. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +180 -0
  23. data/vendor/assets/javascripts/codemirror/{utils → addons/hint}/xml-hint.js +5 -18
  24. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +127 -0
  25. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +14 -0
  26. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +197 -0
  27. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/loadmode.js +0 -0
  28. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/multiplex.js +2 -2
  29. data/vendor/assets/javascripts/codemirror/{utils → addons/mode}/overlay.js +2 -2
  30. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/colorize.js +0 -0
  31. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode-standalone.js +2 -3
  32. data/vendor/assets/javascripts/codemirror/{utils → addons/runmode}/runmode.js +0 -0
  33. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +89 -0
  34. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +60 -0
  35. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/search.js +5 -5
  36. data/vendor/assets/javascripts/codemirror/{utils → addons/search}/searchcursor.js +37 -30
  37. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +39 -0
  38. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +34 -0
  39. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +721 -188
  40. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +6 -6
  41. data/vendor/assets/javascripts/codemirror/modes/clike.js +14 -14
  42. data/vendor/assets/javascripts/codemirror/modes/clojure.js +23 -7
  43. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +2 -2
  44. data/vendor/assets/javascripts/codemirror/modes/css.js +337 -235
  45. data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -12
  46. data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
  47. data/vendor/assets/javascripts/codemirror/modes/gas.js +326 -0
  48. data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -0
  49. data/vendor/assets/javascripts/codemirror/modes/haskell.js +26 -26
  50. data/vendor/assets/javascripts/codemirror/modes/haxe.js +17 -17
  51. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +6 -6
  52. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +43 -23
  53. data/vendor/assets/javascripts/codemirror/modes/javascript.js +78 -33
  54. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +2 -2
  55. data/vendor/assets/javascripts/codemirror/modes/less.js +38 -38
  56. data/vendor/assets/javascripts/codemirror/modes/livescript.js +267 -0
  57. data/vendor/assets/javascripts/codemirror/modes/lua.js +7 -7
  58. data/vendor/assets/javascripts/codemirror/modes/markdown.js +108 -57
  59. data/vendor/assets/javascripts/codemirror/modes/mirc.js +177 -0
  60. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +22 -22
  61. data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -1
  62. data/vendor/assets/javascripts/codemirror/modes/perl.js +791 -791
  63. data/vendor/assets/javascripts/codemirror/modes/php.js +1 -1
  64. data/vendor/assets/javascripts/codemirror/modes/pig.js +163 -163
  65. data/vendor/assets/javascripts/codemirror/modes/python.js +31 -31
  66. data/vendor/assets/javascripts/codemirror/modes/q.js +124 -0
  67. data/vendor/assets/javascripts/codemirror/modes/rst.js +486 -250
  68. data/vendor/assets/javascripts/codemirror/modes/sass.js +3 -3
  69. data/vendor/assets/javascripts/codemirror/modes/scss_test.js +80 -0
  70. data/vendor/assets/javascripts/codemirror/modes/shell.js +2 -2
  71. data/vendor/assets/javascripts/codemirror/modes/sieve.js +10 -10
  72. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +129 -129
  73. data/vendor/assets/javascripts/codemirror/modes/smarty.js +3 -3
  74. data/vendor/assets/javascripts/codemirror/modes/sparql.js +1 -1
  75. data/vendor/assets/javascripts/codemirror/modes/sql.js +23 -23
  76. data/vendor/assets/javascripts/codemirror/modes/stex.js +192 -121
  77. data/vendor/assets/javascripts/codemirror/modes/tcl.js +131 -0
  78. data/vendor/assets/javascripts/codemirror/modes/test.js +64 -0
  79. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +345 -345
  80. data/vendor/assets/javascripts/codemirror/modes/tiki.js +297 -298
  81. data/vendor/assets/javascripts/codemirror/modes/turtle.js +145 -0
  82. data/vendor/assets/javascripts/codemirror/modes/vb.js +31 -32
  83. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +4 -4
  84. data/vendor/assets/javascripts/codemirror/modes/xml.js +10 -6
  85. data/vendor/assets/javascripts/codemirror/modes/xquery.js +55 -55
  86. data/vendor/assets/javascripts/codemirror/modes/yaml.js +90 -90
  87. data/vendor/assets/javascripts/codemirror/modes/z80.js +82 -110
  88. data/vendor/assets/javascripts/codemirror.js +1914 -1115
  89. data/vendor/assets/stylesheets/codemirror/{utils → addons/dialog}/dialog.css +0 -0
  90. data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +38 -0
  91. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +96 -0
  92. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +2 -2
  93. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +0 -1
  94. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +0 -1
  95. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -2
  96. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +5 -5
  97. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +52 -0
  98. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
  99. data/vendor/assets/stylesheets/codemirror.css +16 -10
  100. metadata +60 -52
  101. data/vendor/assets/javascripts/codemirror/modes/mysql.js +0 -203
  102. data/vendor/assets/javascripts/codemirror/modes/plsql.js +0 -216
  103. data/vendor/assets/javascripts/codemirror/utils/collapserange.js +0 -68
  104. data/vendor/assets/javascripts/codemirror/utils/continuelist.js +0 -28
  105. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +0 -183
  106. data/vendor/assets/javascripts/codemirror/utils/formatting.js +0 -114
  107. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +0 -46
  108. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +0 -102
  109. data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +0 -16
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Link to the project's GitHub page:
3
+ * https://github.com/duralog/CodeMirror
4
+ */
5
+ (function() {
6
+ CodeMirror.defineMode('livescript', function(){
7
+ var tokenBase, external;
8
+ tokenBase = function(stream, state){
9
+ var next_rule, nr, i$, len$, r, m;
10
+ if (next_rule = state.next || 'start') {
11
+ state.next = state.next;
12
+ if (Array.isArray(nr = Rules[next_rule])) {
13
+ for (i$ = 0, len$ = nr.length; i$ < len$; ++i$) {
14
+ r = nr[i$];
15
+ if (r.regex && (m = stream.match(r.regex))) {
16
+ state.next = r.next;
17
+ return r.token;
18
+ }
19
+ }
20
+ stream.next();
21
+ return 'error';
22
+ }
23
+ if (stream.match(r = Rules[next_rule])) {
24
+ if (r.regex && stream.match(r.regex)) {
25
+ state.next = r.next;
26
+ return r.token;
27
+ } else {
28
+ stream.next();
29
+ return 'error';
30
+ }
31
+ }
32
+ }
33
+ stream.next();
34
+ return 'error';
35
+ };
36
+ external = {
37
+ startState: function(){
38
+ return {
39
+ next: 'start',
40
+ lastToken: null
41
+ };
42
+ },
43
+ token: function(stream, state){
44
+ var style;
45
+ style = tokenBase(stream, state);
46
+ state.lastToken = {
47
+ style: style,
48
+ indent: stream.indentation(),
49
+ content: stream.current()
50
+ };
51
+ return style.replace(/\./g, ' ');
52
+ },
53
+ indent: function(state){
54
+ var indentation;
55
+ indentation = state.lastToken.indent;
56
+ if (state.lastToken.content.match(indenter)) {
57
+ indentation += 2;
58
+ }
59
+ return indentation;
60
+ }
61
+ };
62
+ return external;
63
+ });
64
+
65
+ var identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';
66
+ var indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');
67
+ var keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
68
+ var stringfill = {
69
+ token: 'string',
70
+ regex: '.+'
71
+ };
72
+ var Rules = {
73
+ start: [
74
+ {
75
+ token: 'comment.doc',
76
+ regex: '/\\*',
77
+ next: 'comment'
78
+ }, {
79
+ token: 'comment',
80
+ regex: '#.*'
81
+ }, {
82
+ token: 'keyword',
83
+ regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend
84
+ }, {
85
+ token: 'constant.language',
86
+ regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
87
+ }, {
88
+ token: 'invalid.illegal',
89
+ regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
90
+ }, {
91
+ token: 'language.support.class',
92
+ regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
93
+ }, {
94
+ token: 'language.support.function',
95
+ regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
96
+ }, {
97
+ token: 'variable.language',
98
+ regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
99
+ }, {
100
+ token: 'identifier',
101
+ regex: identifier + '\\s*:(?![:=])'
102
+ }, {
103
+ token: 'variable',
104
+ regex: identifier
105
+ }, {
106
+ token: 'keyword.operator',
107
+ regex: '(?:\\.{3}|\\s+\\?)'
108
+ }, {
109
+ token: 'keyword.variable',
110
+ regex: '(?:@+|::|\\.\\.)',
111
+ next: 'key'
112
+ }, {
113
+ token: 'keyword.operator',
114
+ regex: '\\.\\s*',
115
+ next: 'key'
116
+ }, {
117
+ token: 'string',
118
+ regex: '\\\\\\S[^\\s,;)}\\]]*'
119
+ }, {
120
+ token: 'string.doc',
121
+ regex: '\'\'\'',
122
+ next: 'qdoc'
123
+ }, {
124
+ token: 'string.doc',
125
+ regex: '"""',
126
+ next: 'qqdoc'
127
+ }, {
128
+ token: 'string',
129
+ regex: '\'',
130
+ next: 'qstring'
131
+ }, {
132
+ token: 'string',
133
+ regex: '"',
134
+ next: 'qqstring'
135
+ }, {
136
+ token: 'string',
137
+ regex: '`',
138
+ next: 'js'
139
+ }, {
140
+ token: 'string',
141
+ regex: '<\\[',
142
+ next: 'words'
143
+ }, {
144
+ token: 'string.regex',
145
+ regex: '//',
146
+ next: 'heregex'
147
+ }, {
148
+ token: 'string.regex',
149
+ regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
150
+ next: 'key'
151
+ }, {
152
+ token: 'constant.numeric',
153
+ regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
154
+ }, {
155
+ token: 'lparen',
156
+ regex: '[({[]'
157
+ }, {
158
+ token: 'rparen',
159
+ regex: '[)}\\]]',
160
+ next: 'key'
161
+ }, {
162
+ token: 'keyword.operator',
163
+ regex: '\\S+'
164
+ }, {
165
+ token: 'text',
166
+ regex: '\\s+'
167
+ }
168
+ ],
169
+ heregex: [
170
+ {
171
+ token: 'string.regex',
172
+ regex: '.*?//[gimy$?]{0,4}',
173
+ next: 'start'
174
+ }, {
175
+ token: 'string.regex',
176
+ regex: '\\s*#{'
177
+ }, {
178
+ token: 'comment.regex',
179
+ regex: '\\s+(?:#.*)?'
180
+ }, {
181
+ token: 'string.regex',
182
+ regex: '\\S+'
183
+ }
184
+ ],
185
+ key: [
186
+ {
187
+ token: 'keyword.operator',
188
+ regex: '[.?@!]+'
189
+ }, {
190
+ token: 'identifier',
191
+ regex: identifier,
192
+ next: 'start'
193
+ }, {
194
+ token: 'text',
195
+ regex: '.',
196
+ next: 'start'
197
+ }
198
+ ],
199
+ comment: [
200
+ {
201
+ token: 'comment.doc',
202
+ regex: '.*?\\*/',
203
+ next: 'start'
204
+ }, {
205
+ token: 'comment.doc',
206
+ regex: '.+'
207
+ }
208
+ ],
209
+ qdoc: [
210
+ {
211
+ token: 'string',
212
+ regex: ".*?'''",
213
+ next: 'key'
214
+ }, stringfill
215
+ ],
216
+ qqdoc: [
217
+ {
218
+ token: 'string',
219
+ regex: '.*?"""',
220
+ next: 'key'
221
+ }, stringfill
222
+ ],
223
+ qstring: [
224
+ {
225
+ token: 'string',
226
+ regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
227
+ next: 'key'
228
+ }, stringfill
229
+ ],
230
+ qqstring: [
231
+ {
232
+ token: 'string',
233
+ regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
234
+ next: 'key'
235
+ }, stringfill
236
+ ],
237
+ js: [
238
+ {
239
+ token: 'string',
240
+ regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
241
+ next: 'key'
242
+ }, stringfill
243
+ ],
244
+ words: [
245
+ {
246
+ token: 'string',
247
+ regex: '.*?\\]>',
248
+ next: 'key'
249
+ }, stringfill
250
+ ]
251
+ };
252
+ for (var idx in Rules) {
253
+ var r = Rules[idx];
254
+ if (Array.isArray(r)) {
255
+ for (var i = 0, len = r.length; i < len; ++i) {
256
+ var rr = r[i];
257
+ if (rr.regex) {
258
+ Rules[idx][i].regex = new RegExp('^' + rr.regex);
259
+ }
260
+ }
261
+ } else if (r.regex) {
262
+ Rules[idx].regex = new RegExp('^' + r.regex);
263
+ }
264
+ }
265
+ })();
266
+
267
+ CodeMirror.defineMIME('text/x-livescript', 'livescript');
@@ -1,7 +1,7 @@
1
1
  // LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
2
2
  // CodeMirror 1 mode.
3
3
  // highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
4
-
4
+
5
5
  CodeMirror.defineMode("lua", function(config, parserConfig) {
6
6
  var indentUnit = config.indentUnit;
7
7
 
@@ -12,7 +12,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
12
12
  return new RegExp("^(?:" + words.join("|") + ")$", "i");
13
13
  }
14
14
  var specials = wordRE(parserConfig.specials || []);
15
-
15
+
16
16
  // long list of standard functions from lua manual
17
17
  var builtins = wordRE([
18
18
  "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
@@ -47,8 +47,8 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
47
47
  "table.concat","table.insert","table.maxn","table.remove","table.sort"
48
48
  ]);
49
49
  var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
50
- "true","function", "end", "if", "then", "else", "do",
51
- "while", "repeat", "until", "for", "in", "local" ]);
50
+ "true","function", "end", "if", "then", "else", "do",
51
+ "while", "repeat", "until", "for", "in", "local" ]);
52
52
 
53
53
  var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
54
54
  var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
@@ -68,7 +68,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
68
68
  return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
69
69
  stream.skipToEnd();
70
70
  return "comment";
71
- }
71
+ }
72
72
  if (ch == "\"" || ch == "'")
73
73
  return (state.cur = string(ch))(stream, state);
74
74
  if (ch == "[" && /[\[=]/.test(stream.peek()))
@@ -108,7 +108,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
108
108
  return "string";
109
109
  };
110
110
  }
111
-
111
+
112
112
  return {
113
113
  startState: function(basecol) {
114
114
  return {basecol: basecol || 0, indentDepth: 0, cur: normal};
@@ -121,7 +121,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
121
121
  if (style == "variable") {
122
122
  if (keywords.test(word)) style = "keyword";
123
123
  else if (builtins.test(word)) style = "builtin";
124
- else if (specials.test(word)) style = "variable-2";
124
+ else if (specials.test(word)) style = "variable-2";
125
125
  }
126
126
  if ((style != "comment") && (style != "string")){
127
127
  if (indentTokens.test(word)) ++state.indentDepth;
@@ -36,27 +36,31 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
36
36
  if (aliases[a] in modes || aliases[a] in mimes)
37
37
  modes[a] = aliases[a];
38
38
  }
39
-
39
+
40
40
  return function (lang) {
41
41
  return modes[lang] ? CodeMirror.getMode(cmCfg, modes[lang]) : null;
42
42
  };
43
43
  }());
44
-
44
+
45
45
  // Should underscores in words open/close em/strong?
46
46
  if (modeCfg.underscoresBreakWords === undefined)
47
47
  modeCfg.underscoresBreakWords = true;
48
-
48
+
49
49
  // Turn on fenced code blocks? ("```" to start/end)
50
50
  if (modeCfg.fencedCodeBlocks === undefined) modeCfg.fencedCodeBlocks = false;
51
-
51
+
52
+ // Turn on task lists? ("- [ ] " and "- [x] ")
53
+ if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
54
+
52
55
  var codeDepth = 0;
53
- var prevLineHasContent = false
54
- , thisLineHasContent = false;
55
56
 
56
57
  var header = 'header'
57
58
  , code = 'comment'
58
- , quote = 'quote'
59
- , list = 'string'
59
+ , quote1 = 'atom'
60
+ , quote2 = 'number'
61
+ , list1 = 'variable-2'
62
+ , list2 = 'variable-3'
63
+ , list3 = 'keyword'
60
64
  , hr = 'hr'
61
65
  , image = 'tag'
62
66
  , linkinline = 'link'
@@ -64,12 +68,12 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
64
68
  , linktext = 'link'
65
69
  , linkhref = 'string'
66
70
  , em = 'em'
67
- , strong = 'strong'
68
- , emstrong = 'emstrong';
71
+ , strong = 'strong';
69
72
 
70
73
  var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/
71
74
  , ulRE = /^[*\-+]\s+/
72
75
  , olRE = /^[0-9]+\.\s+/
76
+ , taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
73
77
  , headerRE = /^(?:\={1,}|-{1,})$/
74
78
  , textRE = /^[^!\[\]*_\\<>` "'(]+/;
75
79
 
@@ -94,43 +98,59 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
94
98
  // Reset STRONG state
95
99
  state.strong = false;
96
100
  // Reset state.quote
97
- state.quote = false;
101
+ state.quote = 0;
98
102
  if (!htmlFound && state.f == htmlBlock) {
99
103
  state.f = inlineNormal;
100
104
  state.block = blockNormal;
101
105
  }
106
+ // Mark this line as blank
107
+ state.thisLineHasContent = false;
102
108
  return null;
103
109
  }
104
110
 
105
111
  function blockNormal(stream, state) {
106
-
112
+
113
+ var prevLineIsList = (state.list !== false);
107
114
  if (state.list !== false && state.indentationDiff >= 0) { // Continued list
108
115
  if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block
109
116
  state.indentation -= state.indentationDiff;
110
117
  }
111
118
  state.list = null;
112
- } else { // No longer a list
119
+ } else if (state.list !== false && state.indentation > 0) {
120
+ state.list = null;
121
+ state.listDepth = Math.floor(state.indentation / 4);
122
+ } else if (state.list !== false) { // No longer a list
113
123
  state.list = false;
124
+ state.listDepth = 0;
114
125
  }
115
-
126
+
116
127
  if (state.indentationDiff >= 4) {
117
128
  state.indentation -= 4;
118
129
  stream.skipToEnd();
119
130
  return code;
120
131
  } else if (stream.eatSpace()) {
121
132
  return null;
122
- } else if (stream.peek() === '#' || (prevLineHasContent && stream.match(headerRE)) ) {
133
+ } else if (stream.peek() === '#' || (state.prevLineHasContent && stream.match(headerRE)) ) {
123
134
  state.header = true;
124
135
  } else if (stream.eat('>')) {
125
136
  state.indentation++;
126
- state.quote = true;
137
+ state.quote = 1;
138
+ stream.eatSpace();
139
+ while (stream.eat('>')) {
140
+ stream.eatSpace();
141
+ state.quote++;
142
+ }
127
143
  } else if (stream.peek() === '[') {
128
144
  return switchInline(stream, state, footnoteLink);
129
145
  } else if (stream.match(hrRE, true)) {
130
146
  return hr;
131
- } else if (stream.match(ulRE, true) || stream.match(olRE, true)) {
147
+ } else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, true) || stream.match(olRE, true))) {
132
148
  state.indentation += 4;
133
149
  state.list = true;
150
+ state.listDepth++;
151
+ if (modeCfg.taskLists && stream.match(taskListRE, false)) {
152
+ state.taskList = true;
153
+ }
134
154
  } else if (modeCfg.fencedCodeBlocks && stream.match(/^```([\w+#]*)/, true)) {
135
155
  // try switching mode
136
156
  state.localMode = getMode(RegExp.$1);
@@ -138,7 +158,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
138
158
  switchBlock(stream, state, local);
139
159
  return code;
140
160
  }
141
-
161
+
142
162
  return switchInline(stream, state, state.inline);
143
163
  }
144
164
 
@@ -173,17 +193,29 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
173
193
  // Inline
174
194
  function getType(state) {
175
195
  var styles = [];
176
-
177
- if (state.strong) { styles.push(state.em ? emstrong : strong); }
178
- else if (state.em) { styles.push(em); }
179
-
196
+
197
+ if (state.taskOpen) { return "meta"; }
198
+ if (state.taskClosed) { return "property"; }
199
+
200
+ if (state.strong) { styles.push(strong); }
201
+ if (state.em) { styles.push(em); }
202
+
180
203
  if (state.linkText) { styles.push(linktext); }
181
-
204
+
182
205
  if (state.code) { styles.push(code); }
183
-
206
+
184
207
  if (state.header) { styles.push(header); }
185
- if (state.quote) { styles.push(quote); }
186
- if (state.list !== false) { styles.push(list); }
208
+ if (state.quote) { styles.push(state.quote % 2 ? quote1 : quote2); }
209
+ if (state.list !== false) {
210
+ var listMod = (state.listDepth - 1) % 3;
211
+ if (!listMod) {
212
+ styles.push(list1);
213
+ } else if (listMod === 1) {
214
+ styles.push(list2);
215
+ } else {
216
+ styles.push(list3);
217
+ }
218
+ }
187
219
 
188
220
  return styles.length ? styles.join(' ') : null;
189
221
  }
@@ -192,26 +224,37 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
192
224
  if (stream.match(textRE, true)) {
193
225
  return getType(state);
194
226
  }
195
- return undefined;
227
+ return undefined;
196
228
  }
197
229
 
198
230
  function inlineNormal(stream, state) {
199
231
  var style = state.text(stream, state);
200
232
  if (typeof style !== 'undefined')
201
233
  return style;
202
-
234
+
203
235
  if (state.list) { // List marker (*, +, -, 1., etc)
204
236
  state.list = null;
205
- return list;
237
+ return getType(state);
238
+ }
239
+
240
+ if (state.taskList) {
241
+ var taskOpen = stream.match(taskListRE, true)[1] !== "x";
242
+ if (taskOpen) state.taskOpen = true;
243
+ else state.taskClosed = true;
244
+ state.taskList = false;
245
+ return getType(state);
206
246
  }
207
-
247
+
248
+ state.taskOpen = false;
249
+ state.taskClosed = false;
250
+
208
251
  var ch = stream.next();
209
-
252
+
210
253
  if (ch === '\\') {
211
254
  stream.next();
212
255
  return getType(state);
213
256
  }
214
-
257
+
215
258
  // Matches link titles present on next line
216
259
  if (state.linkTitle) {
217
260
  state.linkTitle = false;
@@ -225,7 +268,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
225
268
  return linkhref;
226
269
  }
227
270
  }
228
-
271
+
229
272
  // If this block is changed, it may need to be updated in GFM mode
230
273
  if (ch === '`') {
231
274
  var t = getType(state);
@@ -246,7 +289,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
246
289
  } else if (state.code) {
247
290
  return getType(state);
248
291
  }
249
-
292
+
250
293
  if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
251
294
  stream.match(/\[[^\]]*\]/);
252
295
  state.inline = state.f = linkHref;
@@ -264,15 +307,15 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
264
307
  state.inline = state.f = linkHref;
265
308
  return type;
266
309
  }
267
-
310
+
268
311
  if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, true)) {
269
312
  return switchInline(stream, state, inlineElement(linkinline, '>'));
270
313
  }
271
-
314
+
272
315
  if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, true)) {
273
316
  return switchInline(stream, state, inlineElement(linkemail, '>'));
274
317
  }
275
-
318
+
276
319
  if (ch === '<' && stream.match(/^\w/, false)) {
277
320
  if (stream.string.indexOf(">")!=-1) {
278
321
  var atts = stream.string.substring(1,stream.string.indexOf(">"));
@@ -283,12 +326,12 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
283
326
  stream.backUp(1);
284
327
  return switchBlock(stream, state, htmlBlock);
285
328
  }
286
-
329
+
287
330
  if (ch === '<' && stream.match(/^\/\w*?>/)) {
288
331
  state.md_inside = false;
289
332
  return "tag";
290
333
  }
291
-
334
+
292
335
  var ignoreUnderscore = false;
293
336
  if (!modeCfg.underscoresBreakWords) {
294
337
  if (ch === '_' && stream.peek() !== '_' && stream.match(/(\w)/, false)) {
@@ -325,7 +368,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
325
368
  }
326
369
  }
327
370
  }
328
-
371
+
329
372
  return getType(state);
330
373
  }
331
374
 
@@ -371,7 +414,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
371
414
  if (!savedInlineRE[endChar]) {
372
415
  // Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741)
373
416
  endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
374
- // Match any non-endChar, escaped character, as well as the closing
417
+ // Match any non-endChar, escaped character, as well as the closing
375
418
  // endChar.
376
419
  savedInlineRE[endChar] = new RegExp('^(?:[^\\\\]|\\\\.)*?(' + endChar + ')');
377
420
  }
@@ -389,46 +432,54 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
389
432
 
390
433
  return {
391
434
  startState: function() {
392
- prevLineHasContent = false;
393
- thisLineHasContent = false;
394
435
  return {
395
436
  f: blockNormal,
396
-
437
+
438
+ prevLineHasContent: false,
439
+ thisLineHasContent: false,
440
+
397
441
  block: blockNormal,
398
442
  htmlState: CodeMirror.startState(htmlMode),
399
443
  indentation: 0,
400
-
444
+
401
445
  inline: inlineNormal,
402
446
  text: handleText,
403
-
447
+
404
448
  linkText: false,
405
449
  linkTitle: false,
406
450
  em: false,
407
451
  strong: false,
408
452
  header: false,
453
+ taskList: false,
409
454
  list: false,
410
- quote: false
455
+ listDepth: 0,
456
+ quote: 0
411
457
  };
412
458
  },
413
459
 
414
460
  copyState: function(s) {
415
461
  return {
416
462
  f: s.f,
417
-
463
+
464
+ prevLineHasContent: s.prevLineHasContent,
465
+ thisLineHasContent: s.thisLineHasContent,
466
+
418
467
  block: s.block,
419
468
  htmlState: CodeMirror.copyState(htmlMode, s.htmlState),
420
469
  indentation: s.indentation,
421
-
470
+
422
471
  localMode: s.localMode,
423
472
  localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
424
-
473
+
425
474
  inline: s.inline,
426
475
  text: s.text,
427
476
  linkTitle: s.linkTitle,
428
477
  em: s.em,
429
478
  strong: s.strong,
430
479
  header: s.header,
480
+ taskList: s.taskList,
431
481
  list: s.list,
482
+ listDepth: s.listDepth,
432
483
  quote: s.quote,
433
484
  md_inside: s.md_inside
434
485
  };
@@ -437,19 +488,19 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
437
488
  token: function(stream, state) {
438
489
  if (stream.sol()) {
439
490
  if (stream.match(/^\s*$/, true)) {
440
- prevLineHasContent = false;
491
+ state.prevLineHasContent = false;
441
492
  return blankLine(state);
442
493
  } else {
443
- if(thisLineHasContent){
444
- prevLineHasContent = true;
445
- thisLineHasContent = false;
446
- }
447
- thisLineHasContent = true;
494
+ state.prevLineHasContent = state.thisLineHasContent;
495
+ state.thisLineHasContent = true;
448
496
  }
449
497
 
450
498
  // Reset state.header
451
499
  state.header = false;
452
-
500
+
501
+ // Reset state.taskList
502
+ state.taskList = false;
503
+
453
504
  // Reset state.code
454
505
  state.code = false;
455
506