@hpcc-js/codemirror 3.7.4 → 3.7.5

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.
@@ -1,879 +1,879 @@
1
- // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: https://codemirror.net/LICENSE
3
-
4
- /* eslint-disable */
5
-
6
- import CodeMirror from "codemirror";
7
-
8
- CodeMirror.defineMode("markdown", function (cmCfg, modeCfg) {
9
-
10
- var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
11
- var htmlModeMissing = htmlMode.name == "null"
12
-
13
- if (modeCfg.defaultMode === undefined)
14
- modeCfg.defaultMode = "";
15
-
16
- function getMode(name) {
17
- name = name === "" ? modeCfg.defaultMode : name;
18
- if (CodeMirror.findModeByName) {
19
- var found = CodeMirror.findModeByName(name);
20
- if (found) name = found.mime || found.mimes[0];
21
- }
22
- var mode = CodeMirror.getMode(cmCfg, name);
23
- return mode.name == "null" ? null : mode;
24
- }
25
-
26
- // Should characters that affect highlighting be highlighted separate?
27
- // Does not include characters that will be output (such as `1.` and `-` for lists)
28
- if (modeCfg.highlightFormatting === undefined)
29
- modeCfg.highlightFormatting = false;
30
-
31
- // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
32
- // Excess `>` will emit `error` token.
33
- if (modeCfg.maxBlockquoteDepth === undefined)
34
- modeCfg.maxBlockquoteDepth = 0;
35
-
36
- // Turn on task lists? ("- [ ] " and "- [x] ")
37
- if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
38
-
39
- // Turn on strikethrough syntax
40
- if (modeCfg.strikethrough === undefined)
41
- modeCfg.strikethrough = false;
42
-
43
- if (modeCfg.emoji === undefined)
44
- modeCfg.emoji = false;
45
-
46
- if (modeCfg.fencedCodeBlockHighlighting === undefined)
47
- modeCfg.fencedCodeBlockHighlighting = true;
48
-
49
- if (modeCfg.xml === undefined)
50
- modeCfg.xml = true;
51
-
52
- // Allow token types to be overridden by user-provided token types.
53
- if (modeCfg.tokenTypeOverrides === undefined)
54
- modeCfg.tokenTypeOverrides = {};
55
-
56
- var tokenTypes = {
57
- header: "header",
58
- code: "comment",
59
- quote: "quote",
60
- list1: "variable-2",
61
- list2: "variable-3",
62
- list3: "keyword",
63
- hr: "hr",
64
- image: "image",
65
- imageAltText: "image-alt-text",
66
- imageMarker: "image-marker",
67
- formatting: "formatting",
68
- linkInline: "link",
69
- linkEmail: "link",
70
- linkText: "link",
71
- linkHref: "string",
72
- em: "em",
73
- strong: "strong",
74
- strikethrough: "strikethrough",
75
- emoji: "builtin"
76
- };
77
-
78
- for (var tokenType in tokenTypes) {
79
- if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
80
- tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
81
- }
82
- }
83
-
84
- var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
85
- , listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
86
- , taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE
87
- , atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
88
- , setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
89
- , textRE = /^[^#!\[\]*_\\<>` "'(~:]+/
90
- , fencedCodeRE = /^(~~~+|```+)[ \t]*([\w+#-]*)[^\n`]*$/
91
- , linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition
92
- , punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/
93
- , expandedTab = " " // CommonMark specifies tab as 4 spaces
94
-
95
- function switchInline(stream, state, f) {
96
- state.f = state.inline = f;
97
- return f(stream, state);
98
- }
99
-
100
- function switchBlock(stream, state, f) {
101
- state.f = state.block = f;
102
- return f(stream, state);
103
- }
104
-
105
- function lineIsEmpty(line) {
106
- return !line || !/\S/.test(line.string)
107
- }
108
-
109
- // Blocks
110
-
111
- function blankLine(state) {
112
- // Reset linkTitle state
113
- state.linkTitle = false;
114
- state.linkHref = false;
115
- state.linkText = false;
116
- // Reset EM state
117
- state.em = false;
118
- // Reset STRONG state
119
- state.strong = false;
120
- // Reset strikethrough state
121
- state.strikethrough = false;
122
- // Reset state.quote
123
- state.quote = 0;
124
- // Reset state.indentedCode
125
- state.indentedCode = false;
126
- if (state.f == htmlBlock) {
127
- var exit = htmlModeMissing
128
- if (!exit) {
129
- var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
130
- exit = inner.mode.name == "xml" && inner.state.tagStart === null &&
131
- (!inner.state.context && inner.state.tokenize.isInText)
132
- }
133
- if (exit) {
134
- state.f = inlineNormal;
135
- state.block = blockNormal;
136
- state.htmlState = null;
137
- }
138
- }
139
- // Reset state.trailingSpace
140
- state.trailingSpace = 0;
141
- state.trailingSpaceNewLine = false;
142
- // Mark this line as blank
143
- state.prevLine = state.thisLine
144
- state.thisLine = { stream: null }
145
- return null;
146
- }
147
-
148
- function blockNormal(stream, state) {
149
- var firstTokenOnLine = stream.column() === state.indentation;
150
- var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);
151
- var prevLineIsIndentedCode = state.indentedCode;
152
- var prevLineIsHr = state.prevLine.hr;
153
- var prevLineIsList = state.list !== false;
154
- var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;
155
-
156
- state.indentedCode = false;
157
-
158
- var lineIndentation = state.indentation;
159
- // compute once per line (on first token)
160
- if (state.indentationDiff === null) {
161
- state.indentationDiff = state.indentation;
162
- if (prevLineIsList) {
163
- state.list = null;
164
- // While this list item's marker's indentation is less than the deepest
165
- // list item's content's indentation,pop the deepest list item
166
- // indentation off the stack, and update block indentation state
167
- while (lineIndentation < state.listStack[state.listStack.length - 1]) {
168
- state.listStack.pop();
169
- if (state.listStack.length) {
170
- state.indentation = state.listStack[state.listStack.length - 1];
171
- // less than the first list's indent -> the line is no longer a list
172
- } else {
173
- state.list = false;
174
- }
175
- }
176
- if (state.list !== false) {
177
- state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]
178
- }
179
- }
180
- }
181
-
182
- // not comprehensive (currently only for setext detection purposes)
183
- var allowsInlineContinuation = (
184
- !prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&
185
- (!prevLineIsList || !prevLineIsIndentedCode) &&
186
- !state.prevLine.fencedCodeEnd
187
- );
188
-
189
- var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&
190
- state.indentation <= maxNonCodeIndentation && stream.match(hrRE);
191
-
192
- var match = null;
193
- if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||
194
- state.prevLine.header || prevLineLineIsEmpty)) {
195
- stream.skipToEnd();
196
- state.indentedCode = true;
197
- return tokenTypes.code;
198
- } else if (stream.eatSpace()) {
199
- return null;
200
- } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
201
- state.quote = 0;
202
- state.header = match[1].length;
203
- state.thisLine.header = true;
204
- if (modeCfg.highlightFormatting) state.formatting = "header";
205
- state.f = state.inline;
206
- return getType(state);
207
- } else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {
208
- state.quote = firstTokenOnLine ? 1 : state.quote + 1;
209
- if (modeCfg.highlightFormatting) state.formatting = "quote";
210
- stream.eatSpace();
211
- return getType(state);
212
- } else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {
213
- var listType = match[1] ? "ol" : "ul";
214
-
215
- state.indentation = lineIndentation + stream.current().length;
216
- state.list = true;
217
- state.quote = 0;
218
-
219
- // Add this list item's content's indentation to the stack
220
- state.listStack.push(state.indentation);
221
- // Reset inline styles which shouldn't propagate aross list items
222
- state.em = false;
223
- state.strong = false;
224
- state.code = false;
225
- state.strikethrough = false;
226
-
227
- if (modeCfg.taskLists && stream.match(taskListRE, false)) {
228
- state.taskList = true;
229
- }
230
- state.f = state.inline;
231
- if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
232
- return getType(state);
233
- } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {
234
- state.quote = 0;
235
- state.fencedEndRE = new RegExp(match[1] + "+ *$");
236
- // try switching mode
237
- state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2]);
238
- if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
239
- state.f = state.block = local;
240
- if (modeCfg.highlightFormatting) state.formatting = "code-block";
241
- state.code = -1
242
- return getType(state);
243
- // SETEXT has lowest block-scope precedence after HR, so check it after
244
- // the others (code, blockquote, list...)
245
- } else if (
246
- // if setext set, indicates line after ---/===
247
- state.setext || (
248
- // line before ---/===
249
- (!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&
250
- !state.code && !isHr && !linkDefRE.test(stream.string) &&
251
- (match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))
252
- )
253
- ) {
254
- if (!state.setext) {
255
- state.header = match[0].charAt(0) == '=' ? 1 : 2;
256
- state.setext = state.header;
257
- } else {
258
- state.header = state.setext;
259
- // has no effect on type so we can reset it now
260
- state.setext = 0;
261
- stream.skipToEnd();
262
- if (modeCfg.highlightFormatting) state.formatting = "header";
263
- }
264
- state.thisLine.header = true;
265
- state.f = state.inline;
266
- return getType(state);
267
- } else if (isHr) {
268
- stream.skipToEnd();
269
- state.hr = true;
270
- state.thisLine.hr = true;
271
- return tokenTypes.hr;
272
- } else if (stream.peek() === '[') {
273
- return switchInline(stream, state, footnoteLink);
274
- }
275
-
276
- return switchInline(stream, state, state.inline);
277
- }
278
-
279
- function htmlBlock(stream, state) {
280
- var style = htmlMode.token(stream, state.htmlState);
281
- if (!htmlModeMissing) {
282
- var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
283
- if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
284
- (!inner.state.context && inner.state.tokenize.isInText)) ||
285
- (state.md_inside && stream.current().indexOf(">") > -1)) {
286
- state.f = inlineNormal;
287
- state.block = blockNormal;
288
- state.htmlState = null;
289
- }
290
- }
291
- return style;
292
- }
293
-
294
- function local(stream, state) {
295
- var currListInd = state.listStack[state.listStack.length - 1] || 0;
296
- var hasExitedList = state.indentation < currListInd;
297
- var maxFencedEndInd = currListInd + 3;
298
- if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {
299
- if (modeCfg.highlightFormatting) state.formatting = "code-block";
300
- var returnType;
301
- if (!hasExitedList) returnType = getType(state)
302
- state.localMode = state.localState = null;
303
- state.block = blockNormal;
304
- state.f = inlineNormal;
305
- state.fencedEndRE = null;
306
- state.code = 0
307
- state.thisLine.fencedCodeEnd = true;
308
- if (hasExitedList) return switchBlock(stream, state, state.block);
309
- return returnType;
310
- } else if (state.localMode) {
311
- return state.localMode.token(stream, state.localState);
312
- } else {
313
- stream.skipToEnd();
314
- return tokenTypes.code;
315
- }
316
- }
317
-
318
- // Inline
319
- function getType(state) {
320
- var styles = [];
321
-
322
- if (state.formatting) {
323
- styles.push(tokenTypes.formatting);
324
-
325
- if (typeof state.formatting === "string") state.formatting = [state.formatting];
326
-
327
- for (var i = 0; i < state.formatting.length; i++) {
328
- styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
329
-
330
- if (state.formatting[i] === "header") {
331
- styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
332
- }
333
-
334
- // Add `formatting-quote` and `formatting-quote-#` for blockquotes
335
- // Add `error` instead if the maximum blockquote nesting depth is passed
336
- if (state.formatting[i] === "quote") {
337
- if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
338
- styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
339
- } else {
340
- styles.push("error");
341
- }
342
- }
343
- }
344
- }
345
-
346
- if (state.taskOpen) {
347
- styles.push("meta");
348
- return styles.length ? styles.join(' ') : null;
349
- }
350
- if (state.taskClosed) {
351
- styles.push("property");
352
- return styles.length ? styles.join(' ') : null;
353
- }
354
-
355
- if (state.linkHref) {
356
- styles.push(tokenTypes.linkHref, "url");
357
- } else { // Only apply inline styles to non-url text
358
- if (state.strong) { styles.push(tokenTypes.strong); }
359
- if (state.em) { styles.push(tokenTypes.em); }
360
- if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
361
- if (state.emoji) { styles.push(tokenTypes.emoji); }
362
- if (state.linkText) { styles.push(tokenTypes.linkText); }
363
- if (state.code) { styles.push(tokenTypes.code); }
364
- if (state.image) { styles.push(tokenTypes.image); }
365
- if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
366
- if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
367
- }
368
-
369
- if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
370
-
371
- if (state.quote) {
372
- styles.push(tokenTypes.quote);
373
-
374
- // Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
375
- if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
376
- styles.push(tokenTypes.quote + "-" + state.quote);
377
- } else {
378
- styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
379
- }
380
- }
381
-
382
- if (state.list !== false) {
383
- var listMod = (state.listStack.length - 1) % 3;
384
- if (!listMod) {
385
- styles.push(tokenTypes.list1);
386
- } else if (listMod === 1) {
387
- styles.push(tokenTypes.list2);
388
- } else {
389
- styles.push(tokenTypes.list3);
390
- }
391
- }
392
-
393
- if (state.trailingSpaceNewLine) {
394
- styles.push("trailing-space-new-line");
395
- } else if (state.trailingSpace) {
396
- styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
397
- }
398
-
399
- return styles.length ? styles.join(' ') : null;
400
- }
401
-
402
- function handleText(stream, state) {
403
- if (stream.match(textRE, true)) {
404
- return getType(state);
405
- }
406
- return undefined;
407
- }
408
-
409
- function inlineNormal(stream, state) {
410
- var style = state.text(stream, state);
411
- if (typeof style !== 'undefined')
412
- return style;
413
-
414
- if (state.list) { // List marker (*, +, -, 1., etc)
415
- state.list = null;
416
- return getType(state);
417
- }
418
-
419
- if (state.taskList) {
420
- var taskOpen = stream.match(taskListRE, true)[1] === " ";
421
- if (taskOpen) state.taskOpen = true;
422
- else state.taskClosed = true;
423
- if (modeCfg.highlightFormatting) state.formatting = "task";
424
- state.taskList = false;
425
- return getType(state);
426
- }
427
-
428
- state.taskOpen = false;
429
- state.taskClosed = false;
430
-
431
- if (state.header && stream.match(/^#+$/, true)) {
432
- if (modeCfg.highlightFormatting) state.formatting = "header";
433
- return getType(state);
434
- }
435
-
436
- var ch = stream.next();
437
-
438
- // Matches link titles present on next line
439
- if (state.linkTitle) {
440
- state.linkTitle = false;
441
- var matchCh = ch;
442
- if (ch === '(') {
443
- matchCh = ')';
444
- }
445
- matchCh = (matchCh + '').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");
446
- var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
447
- if (stream.match(new RegExp(regex), true)) {
448
- return tokenTypes.linkHref;
449
- }
450
- }
451
-
452
- // If this block is changed, it may need to be updated in GFM mode
453
- if (ch === '`') {
454
- var previousFormatting = state.formatting;
455
- if (modeCfg.highlightFormatting) state.formatting = "code";
456
- stream.eatWhile('`');
457
- var count = stream.current().length
458
- if (state.code == 0 && (!state.quote || count == 1)) {
459
- state.code = count
460
- return getType(state)
461
- } else if (count == state.code) { // Must be exact
462
- var t = getType(state)
463
- state.code = 0
464
- return t
465
- } else {
466
- state.formatting = previousFormatting
467
- return getType(state)
468
- }
469
- } else if (state.code) {
470
- return getType(state);
471
- }
472
-
473
- if (ch === '\\') {
474
- stream.next();
475
- if (modeCfg.highlightFormatting) {
476
- var type = getType(state);
477
- var formattingEscape = tokenTypes.formatting + "-escape";
478
- return type ? type + " " + formattingEscape : formattingEscape;
479
- }
480
- }
481
-
482
- if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
483
- state.imageMarker = true;
484
- state.image = true;
485
- if (modeCfg.highlightFormatting) state.formatting = "image";
486
- return getType(state);
487
- }
488
-
489
- if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {
490
- state.imageMarker = false;
491
- state.imageAltText = true
492
- if (modeCfg.highlightFormatting) state.formatting = "image";
493
- return getType(state);
494
- }
495
-
496
- if (ch === ']' && state.imageAltText) {
497
- if (modeCfg.highlightFormatting) state.formatting = "image";
498
- var type = getType(state);
499
- state.imageAltText = false;
500
- state.image = false;
501
- state.inline = state.f = linkHref;
502
- return type;
503
- }
504
-
505
- if (ch === '[' && !state.image) {
506
- if (state.linkText && stream.match(/^.*?\]/)) return getType(state)
507
- state.linkText = true;
508
- if (modeCfg.highlightFormatting) state.formatting = "link";
509
- return getType(state);
510
- }
511
-
512
- if (ch === ']' && state.linkText) {
513
- if (modeCfg.highlightFormatting) state.formatting = "link";
514
- var type = getType(state);
515
- state.linkText = false;
516
- state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal
517
- return type;
518
- }
519
-
520
- if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
521
- state.f = state.inline = linkInline;
522
- if (modeCfg.highlightFormatting) state.formatting = "link";
523
- var type = getType(state);
524
- if (type) {
525
- type += " ";
526
- } else {
527
- type = "";
528
- }
529
- return type + tokenTypes.linkInline;
530
- }
531
-
532
- if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
533
- state.f = state.inline = linkInline;
534
- if (modeCfg.highlightFormatting) state.formatting = "link";
535
- var type = getType(state);
536
- if (type) {
537
- type += " ";
538
- } else {
539
- type = "";
540
- }
541
- return type + tokenTypes.linkEmail;
542
- }
543
-
544
- if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
545
- var end = stream.string.indexOf(">", stream.pos);
546
- if (end != -1) {
547
- var atts = stream.string.substring(stream.start, end);
548
- if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
549
- }
550
- stream.backUp(1);
551
- state.htmlState = CodeMirror.startState(htmlMode);
552
- return switchBlock(stream, state, htmlBlock);
553
- }
554
-
555
- if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {
556
- state.md_inside = false;
557
- return "tag";
558
- } else if (ch === "*" || ch === "_") {
559
- var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)
560
- while (len < 3 && stream.eat(ch)) len++
561
- var after = stream.peek() || " "
562
- // See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
563
- var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))
564
- var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))
565
- var setEm = null, setStrong = null
566
- if (len % 2) { // Em
567
- if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
568
- setEm = true
569
- else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
570
- setEm = false
571
- }
572
- if (len > 1) { // Strong
573
- if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
574
- setStrong = true
575
- else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
576
- setStrong = false
577
- }
578
- if (setStrong != null || setEm != null) {
579
- if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"
580
- if (setEm === true) state.em = ch
581
- if (setStrong === true) state.strong = ch
582
- var t = getType(state)
583
- if (setEm === false) state.em = false
584
- if (setStrong === false) state.strong = false
585
- return t
586
- }
587
- } else if (ch === ' ') {
588
- if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
589
- if (stream.peek() === ' ') { // Surrounded by spaces, ignore
590
- return getType(state);
591
- } else { // Not surrounded by spaces, back up pointer
592
- stream.backUp(1);
593
- }
594
- }
595
- }
596
-
597
- if (modeCfg.strikethrough) {
598
- if (ch === '~' && stream.eatWhile(ch)) {
599
- if (state.strikethrough) {// Remove strikethrough
600
- if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
601
- var t = getType(state);
602
- state.strikethrough = false;
603
- return t;
604
- } else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
605
- state.strikethrough = true;
606
- if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
607
- return getType(state);
608
- }
609
- } else if (ch === ' ') {
610
- if (stream.match(/^~~/, true)) { // Probably surrounded by space
611
- if (stream.peek() === ' ') { // Surrounded by spaces, ignore
612
- return getType(state);
613
- } else { // Not surrounded by spaces, back up pointer
614
- stream.backUp(2);
615
- }
616
- }
617
- }
618
- }
619
-
620
- if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {
621
- state.emoji = true;
622
- if (modeCfg.highlightFormatting) state.formatting = "emoji";
623
- var retType = getType(state);
624
- state.emoji = false;
625
- return retType;
626
- }
627
-
628
- if (ch === ' ') {
629
- if (stream.match(/^ +$/, false)) {
630
- state.trailingSpace++;
631
- } else if (state.trailingSpace) {
632
- state.trailingSpaceNewLine = true;
633
- }
634
- }
635
-
636
- return getType(state);
637
- }
638
-
639
- function linkInline(stream, state) {
640
- var ch = stream.next();
641
-
642
- if (ch === ">") {
643
- state.f = state.inline = inlineNormal;
644
- if (modeCfg.highlightFormatting) state.formatting = "link";
645
- var type = getType(state);
646
- if (type) {
647
- type += " ";
648
- } else {
649
- type = "";
650
- }
651
- return type + tokenTypes.linkInline;
652
- }
653
-
654
- stream.match(/^[^>]+/, true);
655
-
656
- return tokenTypes.linkInline;
657
- }
658
-
659
- function linkHref(stream, state) {
660
- // Check if space, and return NULL if so (to avoid marking the space)
661
- if (stream.eatSpace()) {
662
- return null;
663
- }
664
- var ch = stream.next();
665
- if (ch === '(' || ch === '[') {
666
- state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
667
- if (modeCfg.highlightFormatting) state.formatting = "link-string";
668
- state.linkHref = true;
669
- return getType(state);
670
- }
671
- return 'error';
672
- }
673
-
674
- var linkRE = {
675
- ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
676
- "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/
677
- }
678
-
679
- function getLinkHrefInside(endChar) {
680
- return function (stream, state) {
681
- var ch = stream.next();
682
-
683
- if (ch === endChar) {
684
- state.f = state.inline = inlineNormal;
685
- if (modeCfg.highlightFormatting) state.formatting = "link-string";
686
- var returnState = getType(state);
687
- state.linkHref = false;
688
- return returnState;
689
- }
690
-
691
- stream.match(linkRE[endChar])
692
- state.linkHref = true;
693
- return getType(state);
694
- };
695
- }
696
-
697
- function footnoteLink(stream, state) {
698
- if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
699
- state.f = footnoteLinkInside;
700
- stream.next(); // Consume [
701
- if (modeCfg.highlightFormatting) state.formatting = "link";
702
- state.linkText = true;
703
- return getType(state);
704
- }
705
- return switchInline(stream, state, inlineNormal);
706
- }
707
-
708
- function footnoteLinkInside(stream, state) {
709
- if (stream.match(/^\]:/, true)) {
710
- state.f = state.inline = footnoteUrl;
711
- if (modeCfg.highlightFormatting) state.formatting = "link";
712
- var returnType = getType(state);
713
- state.linkText = false;
714
- return returnType;
715
- }
716
-
717
- stream.match(/^([^\]\\]|\\.)+/, true);
718
-
719
- return tokenTypes.linkText;
720
- }
721
-
722
- function footnoteUrl(stream, state) {
723
- // Check if space, and return NULL if so (to avoid marking the space)
724
- if (stream.eatSpace()) {
725
- return null;
726
- }
727
- // Match URL
728
- stream.match(/^[^\s]+/, true);
729
- // Check for link title
730
- if (stream.peek() === undefined) { // End of line, set flag to check next line
731
- state.linkTitle = true;
732
- } else { // More content on line, check if link title
733
- stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
734
- }
735
- state.f = state.inline = inlineNormal;
736
- return tokenTypes.linkHref + " url";
737
- }
738
-
739
- var mode = {
740
- startState: function () {
741
- return {
742
- f: blockNormal,
743
-
744
- prevLine: { stream: null },
745
- thisLine: { stream: null },
746
-
747
- block: blockNormal,
748
- htmlState: null,
749
- indentation: 0,
750
-
751
- inline: inlineNormal,
752
- text: handleText,
753
-
754
- formatting: false,
755
- linkText: false,
756
- linkHref: false,
757
- linkTitle: false,
758
- code: 0,
759
- em: false,
760
- strong: false,
761
- header: 0,
762
- setext: 0,
763
- hr: false,
764
- taskList: false,
765
- list: false,
766
- listStack: [],
767
- quote: 0,
768
- trailingSpace: 0,
769
- trailingSpaceNewLine: false,
770
- strikethrough: false,
771
- emoji: false,
772
- fencedEndRE: null
773
- };
774
- },
775
-
776
- copyState: function (s) {
777
- return {
778
- f: s.f,
779
-
780
- prevLine: s.prevLine,
781
- thisLine: s.thisLine,
782
-
783
- block: s.block,
784
- htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
785
- indentation: s.indentation,
786
-
787
- localMode: s.localMode,
788
- localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
789
-
790
- inline: s.inline,
791
- text: s.text,
792
- formatting: false,
793
- linkText: s.linkText,
794
- linkTitle: s.linkTitle,
795
- linkHref: s.linkHref,
796
- code: s.code,
797
- em: s.em,
798
- strong: s.strong,
799
- strikethrough: s.strikethrough,
800
- emoji: s.emoji,
801
- header: s.header,
802
- setext: s.setext,
803
- hr: s.hr,
804
- taskList: s.taskList,
805
- list: s.list,
806
- listStack: s.listStack.slice(0),
807
- quote: s.quote,
808
- indentedCode: s.indentedCode,
809
- trailingSpace: s.trailingSpace,
810
- trailingSpaceNewLine: s.trailingSpaceNewLine,
811
- md_inside: s.md_inside,
812
- fencedEndRE: s.fencedEndRE
813
- };
814
- },
815
-
816
- token: function (stream, state) {
817
-
818
- // Reset state.formatting
819
- state.formatting = false;
820
-
821
- if (stream != state.thisLine.stream) {
822
- state.header = 0;
823
- state.hr = false;
824
-
825
- if (stream.match(/^\s*$/, true)) {
826
- blankLine(state);
827
- return null;
828
- }
829
-
830
- state.prevLine = state.thisLine
831
- state.thisLine = { stream: stream }
832
-
833
- // Reset state.taskList
834
- state.taskList = false;
835
-
836
- // Reset state.trailingSpace
837
- state.trailingSpace = 0;
838
- state.trailingSpaceNewLine = false;
839
-
840
- if (!state.localState) {
841
- state.f = state.block;
842
- if (state.f != htmlBlock) {
843
- var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;
844
- state.indentation = indentation;
845
- state.indentationDiff = null;
846
- if (indentation > 0) return null;
847
- }
848
- }
849
- }
850
- return state.f(stream, state);
851
- },
852
-
853
- innerMode: function (state) {
854
- if (state.block == htmlBlock) return { state: state.htmlState, mode: htmlMode };
855
- if (state.localState) return { state: state.localState, mode: state.localMode };
856
- return { state: state, mode: mode };
857
- },
858
-
859
- indent: function (state, textAfter, line) {
860
- if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)
861
- if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)
862
- return CodeMirror.Pass
863
- },
864
-
865
- blankLine: blankLine,
866
-
867
- getType: getType,
868
-
869
- blockCommentStart: "<!--",
870
- blockCommentEnd: "-->",
871
- closeBrackets: "()[]{}''\"\"``",
872
- fold: "markdown"
873
- };
874
- return mode;
875
- }, "xml");
876
-
877
- CodeMirror.defineMIME("text/markdown", "markdown");
878
-
879
- CodeMirror.defineMIME("text/x-markdown", "markdown");
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ /* eslint-disable */
5
+
6
+ import CodeMirror from "codemirror";
7
+
8
+ CodeMirror.defineMode("markdown", function (cmCfg, modeCfg) {
9
+
10
+ var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
11
+ var htmlModeMissing = htmlMode.name == "null"
12
+
13
+ if (modeCfg.defaultMode === undefined)
14
+ modeCfg.defaultMode = "";
15
+
16
+ function getMode(name) {
17
+ name = name === "" ? modeCfg.defaultMode : name;
18
+ if (CodeMirror.findModeByName) {
19
+ var found = CodeMirror.findModeByName(name);
20
+ if (found) name = found.mime || found.mimes[0];
21
+ }
22
+ var mode = CodeMirror.getMode(cmCfg, name);
23
+ return mode.name == "null" ? null : mode;
24
+ }
25
+
26
+ // Should characters that affect highlighting be highlighted separate?
27
+ // Does not include characters that will be output (such as `1.` and `-` for lists)
28
+ if (modeCfg.highlightFormatting === undefined)
29
+ modeCfg.highlightFormatting = false;
30
+
31
+ // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
32
+ // Excess `>` will emit `error` token.
33
+ if (modeCfg.maxBlockquoteDepth === undefined)
34
+ modeCfg.maxBlockquoteDepth = 0;
35
+
36
+ // Turn on task lists? ("- [ ] " and "- [x] ")
37
+ if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
38
+
39
+ // Turn on strikethrough syntax
40
+ if (modeCfg.strikethrough === undefined)
41
+ modeCfg.strikethrough = false;
42
+
43
+ if (modeCfg.emoji === undefined)
44
+ modeCfg.emoji = false;
45
+
46
+ if (modeCfg.fencedCodeBlockHighlighting === undefined)
47
+ modeCfg.fencedCodeBlockHighlighting = true;
48
+
49
+ if (modeCfg.xml === undefined)
50
+ modeCfg.xml = true;
51
+
52
+ // Allow token types to be overridden by user-provided token types.
53
+ if (modeCfg.tokenTypeOverrides === undefined)
54
+ modeCfg.tokenTypeOverrides = {};
55
+
56
+ var tokenTypes = {
57
+ header: "header",
58
+ code: "comment",
59
+ quote: "quote",
60
+ list1: "variable-2",
61
+ list2: "variable-3",
62
+ list3: "keyword",
63
+ hr: "hr",
64
+ image: "image",
65
+ imageAltText: "image-alt-text",
66
+ imageMarker: "image-marker",
67
+ formatting: "formatting",
68
+ linkInline: "link",
69
+ linkEmail: "link",
70
+ linkText: "link",
71
+ linkHref: "string",
72
+ em: "em",
73
+ strong: "strong",
74
+ strikethrough: "strikethrough",
75
+ emoji: "builtin"
76
+ };
77
+
78
+ for (var tokenType in tokenTypes) {
79
+ if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
80
+ tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
81
+ }
82
+ }
83
+
84
+ var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
85
+ , listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
86
+ , taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE
87
+ , atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
88
+ , setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
89
+ , textRE = /^[^#!\[\]*_\\<>` "'(~:]+/
90
+ , fencedCodeRE = /^(~~~+|```+)[ \t]*([\w+#-]*)[^\n`]*$/
91
+ , linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition
92
+ , punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/
93
+ , expandedTab = " " // CommonMark specifies tab as 4 spaces
94
+
95
+ function switchInline(stream, state, f) {
96
+ state.f = state.inline = f;
97
+ return f(stream, state);
98
+ }
99
+
100
+ function switchBlock(stream, state, f) {
101
+ state.f = state.block = f;
102
+ return f(stream, state);
103
+ }
104
+
105
+ function lineIsEmpty(line) {
106
+ return !line || !/\S/.test(line.string)
107
+ }
108
+
109
+ // Blocks
110
+
111
+ function blankLine(state) {
112
+ // Reset linkTitle state
113
+ state.linkTitle = false;
114
+ state.linkHref = false;
115
+ state.linkText = false;
116
+ // Reset EM state
117
+ state.em = false;
118
+ // Reset STRONG state
119
+ state.strong = false;
120
+ // Reset strikethrough state
121
+ state.strikethrough = false;
122
+ // Reset state.quote
123
+ state.quote = 0;
124
+ // Reset state.indentedCode
125
+ state.indentedCode = false;
126
+ if (state.f == htmlBlock) {
127
+ var exit = htmlModeMissing
128
+ if (!exit) {
129
+ var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
130
+ exit = inner.mode.name == "xml" && inner.state.tagStart === null &&
131
+ (!inner.state.context && inner.state.tokenize.isInText)
132
+ }
133
+ if (exit) {
134
+ state.f = inlineNormal;
135
+ state.block = blockNormal;
136
+ state.htmlState = null;
137
+ }
138
+ }
139
+ // Reset state.trailingSpace
140
+ state.trailingSpace = 0;
141
+ state.trailingSpaceNewLine = false;
142
+ // Mark this line as blank
143
+ state.prevLine = state.thisLine
144
+ state.thisLine = { stream: null }
145
+ return null;
146
+ }
147
+
148
+ function blockNormal(stream, state) {
149
+ var firstTokenOnLine = stream.column() === state.indentation;
150
+ var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);
151
+ var prevLineIsIndentedCode = state.indentedCode;
152
+ var prevLineIsHr = state.prevLine.hr;
153
+ var prevLineIsList = state.list !== false;
154
+ var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;
155
+
156
+ state.indentedCode = false;
157
+
158
+ var lineIndentation = state.indentation;
159
+ // compute once per line (on first token)
160
+ if (state.indentationDiff === null) {
161
+ state.indentationDiff = state.indentation;
162
+ if (prevLineIsList) {
163
+ state.list = null;
164
+ // While this list item's marker's indentation is less than the deepest
165
+ // list item's content's indentation,pop the deepest list item
166
+ // indentation off the stack, and update block indentation state
167
+ while (lineIndentation < state.listStack[state.listStack.length - 1]) {
168
+ state.listStack.pop();
169
+ if (state.listStack.length) {
170
+ state.indentation = state.listStack[state.listStack.length - 1];
171
+ // less than the first list's indent -> the line is no longer a list
172
+ } else {
173
+ state.list = false;
174
+ }
175
+ }
176
+ if (state.list !== false) {
177
+ state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]
178
+ }
179
+ }
180
+ }
181
+
182
+ // not comprehensive (currently only for setext detection purposes)
183
+ var allowsInlineContinuation = (
184
+ !prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&
185
+ (!prevLineIsList || !prevLineIsIndentedCode) &&
186
+ !state.prevLine.fencedCodeEnd
187
+ );
188
+
189
+ var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&
190
+ state.indentation <= maxNonCodeIndentation && stream.match(hrRE);
191
+
192
+ var match = null;
193
+ if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||
194
+ state.prevLine.header || prevLineLineIsEmpty)) {
195
+ stream.skipToEnd();
196
+ state.indentedCode = true;
197
+ return tokenTypes.code;
198
+ } else if (stream.eatSpace()) {
199
+ return null;
200
+ } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
201
+ state.quote = 0;
202
+ state.header = match[1].length;
203
+ state.thisLine.header = true;
204
+ if (modeCfg.highlightFormatting) state.formatting = "header";
205
+ state.f = state.inline;
206
+ return getType(state);
207
+ } else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {
208
+ state.quote = firstTokenOnLine ? 1 : state.quote + 1;
209
+ if (modeCfg.highlightFormatting) state.formatting = "quote";
210
+ stream.eatSpace();
211
+ return getType(state);
212
+ } else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {
213
+ var listType = match[1] ? "ol" : "ul";
214
+
215
+ state.indentation = lineIndentation + stream.current().length;
216
+ state.list = true;
217
+ state.quote = 0;
218
+
219
+ // Add this list item's content's indentation to the stack
220
+ state.listStack.push(state.indentation);
221
+ // Reset inline styles which shouldn't propagate aross list items
222
+ state.em = false;
223
+ state.strong = false;
224
+ state.code = false;
225
+ state.strikethrough = false;
226
+
227
+ if (modeCfg.taskLists && stream.match(taskListRE, false)) {
228
+ state.taskList = true;
229
+ }
230
+ state.f = state.inline;
231
+ if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
232
+ return getType(state);
233
+ } else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {
234
+ state.quote = 0;
235
+ state.fencedEndRE = new RegExp(match[1] + "+ *$");
236
+ // try switching mode
237
+ state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2]);
238
+ if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
239
+ state.f = state.block = local;
240
+ if (modeCfg.highlightFormatting) state.formatting = "code-block";
241
+ state.code = -1
242
+ return getType(state);
243
+ // SETEXT has lowest block-scope precedence after HR, so check it after
244
+ // the others (code, blockquote, list...)
245
+ } else if (
246
+ // if setext set, indicates line after ---/===
247
+ state.setext || (
248
+ // line before ---/===
249
+ (!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&
250
+ !state.code && !isHr && !linkDefRE.test(stream.string) &&
251
+ (match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))
252
+ )
253
+ ) {
254
+ if (!state.setext) {
255
+ state.header = match[0].charAt(0) == '=' ? 1 : 2;
256
+ state.setext = state.header;
257
+ } else {
258
+ state.header = state.setext;
259
+ // has no effect on type so we can reset it now
260
+ state.setext = 0;
261
+ stream.skipToEnd();
262
+ if (modeCfg.highlightFormatting) state.formatting = "header";
263
+ }
264
+ state.thisLine.header = true;
265
+ state.f = state.inline;
266
+ return getType(state);
267
+ } else if (isHr) {
268
+ stream.skipToEnd();
269
+ state.hr = true;
270
+ state.thisLine.hr = true;
271
+ return tokenTypes.hr;
272
+ } else if (stream.peek() === '[') {
273
+ return switchInline(stream, state, footnoteLink);
274
+ }
275
+
276
+ return switchInline(stream, state, state.inline);
277
+ }
278
+
279
+ function htmlBlock(stream, state) {
280
+ var style = htmlMode.token(stream, state.htmlState);
281
+ if (!htmlModeMissing) {
282
+ var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
283
+ if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
284
+ (!inner.state.context && inner.state.tokenize.isInText)) ||
285
+ (state.md_inside && stream.current().indexOf(">") > -1)) {
286
+ state.f = inlineNormal;
287
+ state.block = blockNormal;
288
+ state.htmlState = null;
289
+ }
290
+ }
291
+ return style;
292
+ }
293
+
294
+ function local(stream, state) {
295
+ var currListInd = state.listStack[state.listStack.length - 1] || 0;
296
+ var hasExitedList = state.indentation < currListInd;
297
+ var maxFencedEndInd = currListInd + 3;
298
+ if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {
299
+ if (modeCfg.highlightFormatting) state.formatting = "code-block";
300
+ var returnType;
301
+ if (!hasExitedList) returnType = getType(state)
302
+ state.localMode = state.localState = null;
303
+ state.block = blockNormal;
304
+ state.f = inlineNormal;
305
+ state.fencedEndRE = null;
306
+ state.code = 0
307
+ state.thisLine.fencedCodeEnd = true;
308
+ if (hasExitedList) return switchBlock(stream, state, state.block);
309
+ return returnType;
310
+ } else if (state.localMode) {
311
+ return state.localMode.token(stream, state.localState);
312
+ } else {
313
+ stream.skipToEnd();
314
+ return tokenTypes.code;
315
+ }
316
+ }
317
+
318
+ // Inline
319
+ function getType(state) {
320
+ var styles = [];
321
+
322
+ if (state.formatting) {
323
+ styles.push(tokenTypes.formatting);
324
+
325
+ if (typeof state.formatting === "string") state.formatting = [state.formatting];
326
+
327
+ for (var i = 0; i < state.formatting.length; i++) {
328
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
329
+
330
+ if (state.formatting[i] === "header") {
331
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
332
+ }
333
+
334
+ // Add `formatting-quote` and `formatting-quote-#` for blockquotes
335
+ // Add `error` instead if the maximum blockquote nesting depth is passed
336
+ if (state.formatting[i] === "quote") {
337
+ if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
338
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
339
+ } else {
340
+ styles.push("error");
341
+ }
342
+ }
343
+ }
344
+ }
345
+
346
+ if (state.taskOpen) {
347
+ styles.push("meta");
348
+ return styles.length ? styles.join(' ') : null;
349
+ }
350
+ if (state.taskClosed) {
351
+ styles.push("property");
352
+ return styles.length ? styles.join(' ') : null;
353
+ }
354
+
355
+ if (state.linkHref) {
356
+ styles.push(tokenTypes.linkHref, "url");
357
+ } else { // Only apply inline styles to non-url text
358
+ if (state.strong) { styles.push(tokenTypes.strong); }
359
+ if (state.em) { styles.push(tokenTypes.em); }
360
+ if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
361
+ if (state.emoji) { styles.push(tokenTypes.emoji); }
362
+ if (state.linkText) { styles.push(tokenTypes.linkText); }
363
+ if (state.code) { styles.push(tokenTypes.code); }
364
+ if (state.image) { styles.push(tokenTypes.image); }
365
+ if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
366
+ if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
367
+ }
368
+
369
+ if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
370
+
371
+ if (state.quote) {
372
+ styles.push(tokenTypes.quote);
373
+
374
+ // Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
375
+ if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
376
+ styles.push(tokenTypes.quote + "-" + state.quote);
377
+ } else {
378
+ styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
379
+ }
380
+ }
381
+
382
+ if (state.list !== false) {
383
+ var listMod = (state.listStack.length - 1) % 3;
384
+ if (!listMod) {
385
+ styles.push(tokenTypes.list1);
386
+ } else if (listMod === 1) {
387
+ styles.push(tokenTypes.list2);
388
+ } else {
389
+ styles.push(tokenTypes.list3);
390
+ }
391
+ }
392
+
393
+ if (state.trailingSpaceNewLine) {
394
+ styles.push("trailing-space-new-line");
395
+ } else if (state.trailingSpace) {
396
+ styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
397
+ }
398
+
399
+ return styles.length ? styles.join(' ') : null;
400
+ }
401
+
402
+ function handleText(stream, state) {
403
+ if (stream.match(textRE, true)) {
404
+ return getType(state);
405
+ }
406
+ return undefined;
407
+ }
408
+
409
+ function inlineNormal(stream, state) {
410
+ var style = state.text(stream, state);
411
+ if (typeof style !== 'undefined')
412
+ return style;
413
+
414
+ if (state.list) { // List marker (*, +, -, 1., etc)
415
+ state.list = null;
416
+ return getType(state);
417
+ }
418
+
419
+ if (state.taskList) {
420
+ var taskOpen = stream.match(taskListRE, true)[1] === " ";
421
+ if (taskOpen) state.taskOpen = true;
422
+ else state.taskClosed = true;
423
+ if (modeCfg.highlightFormatting) state.formatting = "task";
424
+ state.taskList = false;
425
+ return getType(state);
426
+ }
427
+
428
+ state.taskOpen = false;
429
+ state.taskClosed = false;
430
+
431
+ if (state.header && stream.match(/^#+$/, true)) {
432
+ if (modeCfg.highlightFormatting) state.formatting = "header";
433
+ return getType(state);
434
+ }
435
+
436
+ var ch = stream.next();
437
+
438
+ // Matches link titles present on next line
439
+ if (state.linkTitle) {
440
+ state.linkTitle = false;
441
+ var matchCh = ch;
442
+ if (ch === '(') {
443
+ matchCh = ')';
444
+ }
445
+ matchCh = (matchCh + '').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");
446
+ var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
447
+ if (stream.match(new RegExp(regex), true)) {
448
+ return tokenTypes.linkHref;
449
+ }
450
+ }
451
+
452
+ // If this block is changed, it may need to be updated in GFM mode
453
+ if (ch === '`') {
454
+ var previousFormatting = state.formatting;
455
+ if (modeCfg.highlightFormatting) state.formatting = "code";
456
+ stream.eatWhile('`');
457
+ var count = stream.current().length
458
+ if (state.code == 0 && (!state.quote || count == 1)) {
459
+ state.code = count
460
+ return getType(state)
461
+ } else if (count == state.code) { // Must be exact
462
+ var t = getType(state)
463
+ state.code = 0
464
+ return t
465
+ } else {
466
+ state.formatting = previousFormatting
467
+ return getType(state)
468
+ }
469
+ } else if (state.code) {
470
+ return getType(state);
471
+ }
472
+
473
+ if (ch === '\\') {
474
+ stream.next();
475
+ if (modeCfg.highlightFormatting) {
476
+ var type = getType(state);
477
+ var formattingEscape = tokenTypes.formatting + "-escape";
478
+ return type ? type + " " + formattingEscape : formattingEscape;
479
+ }
480
+ }
481
+
482
+ if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
483
+ state.imageMarker = true;
484
+ state.image = true;
485
+ if (modeCfg.highlightFormatting) state.formatting = "image";
486
+ return getType(state);
487
+ }
488
+
489
+ if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {
490
+ state.imageMarker = false;
491
+ state.imageAltText = true
492
+ if (modeCfg.highlightFormatting) state.formatting = "image";
493
+ return getType(state);
494
+ }
495
+
496
+ if (ch === ']' && state.imageAltText) {
497
+ if (modeCfg.highlightFormatting) state.formatting = "image";
498
+ var type = getType(state);
499
+ state.imageAltText = false;
500
+ state.image = false;
501
+ state.inline = state.f = linkHref;
502
+ return type;
503
+ }
504
+
505
+ if (ch === '[' && !state.image) {
506
+ if (state.linkText && stream.match(/^.*?\]/)) return getType(state)
507
+ state.linkText = true;
508
+ if (modeCfg.highlightFormatting) state.formatting = "link";
509
+ return getType(state);
510
+ }
511
+
512
+ if (ch === ']' && state.linkText) {
513
+ if (modeCfg.highlightFormatting) state.formatting = "link";
514
+ var type = getType(state);
515
+ state.linkText = false;
516
+ state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal
517
+ return type;
518
+ }
519
+
520
+ if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
521
+ state.f = state.inline = linkInline;
522
+ if (modeCfg.highlightFormatting) state.formatting = "link";
523
+ var type = getType(state);
524
+ if (type) {
525
+ type += " ";
526
+ } else {
527
+ type = "";
528
+ }
529
+ return type + tokenTypes.linkInline;
530
+ }
531
+
532
+ if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
533
+ state.f = state.inline = linkInline;
534
+ if (modeCfg.highlightFormatting) state.formatting = "link";
535
+ var type = getType(state);
536
+ if (type) {
537
+ type += " ";
538
+ } else {
539
+ type = "";
540
+ }
541
+ return type + tokenTypes.linkEmail;
542
+ }
543
+
544
+ if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {
545
+ var end = stream.string.indexOf(">", stream.pos);
546
+ if (end != -1) {
547
+ var atts = stream.string.substring(stream.start, end);
548
+ if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
549
+ }
550
+ stream.backUp(1);
551
+ state.htmlState = CodeMirror.startState(htmlMode);
552
+ return switchBlock(stream, state, htmlBlock);
553
+ }
554
+
555
+ if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {
556
+ state.md_inside = false;
557
+ return "tag";
558
+ } else if (ch === "*" || ch === "_") {
559
+ var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)
560
+ while (len < 3 && stream.eat(ch)) len++
561
+ var after = stream.peek() || " "
562
+ // See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis
563
+ var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))
564
+ var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))
565
+ var setEm = null, setStrong = null
566
+ if (len % 2) { // Em
567
+ if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
568
+ setEm = true
569
+ else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
570
+ setEm = false
571
+ }
572
+ if (len > 1) { // Strong
573
+ if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))
574
+ setStrong = true
575
+ else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))
576
+ setStrong = false
577
+ }
578
+ if (setStrong != null || setEm != null) {
579
+ if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"
580
+ if (setEm === true) state.em = ch
581
+ if (setStrong === true) state.strong = ch
582
+ var t = getType(state)
583
+ if (setEm === false) state.em = false
584
+ if (setStrong === false) state.strong = false
585
+ return t
586
+ }
587
+ } else if (ch === ' ') {
588
+ if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
589
+ if (stream.peek() === ' ') { // Surrounded by spaces, ignore
590
+ return getType(state);
591
+ } else { // Not surrounded by spaces, back up pointer
592
+ stream.backUp(1);
593
+ }
594
+ }
595
+ }
596
+
597
+ if (modeCfg.strikethrough) {
598
+ if (ch === '~' && stream.eatWhile(ch)) {
599
+ if (state.strikethrough) {// Remove strikethrough
600
+ if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
601
+ var t = getType(state);
602
+ state.strikethrough = false;
603
+ return t;
604
+ } else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
605
+ state.strikethrough = true;
606
+ if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
607
+ return getType(state);
608
+ }
609
+ } else if (ch === ' ') {
610
+ if (stream.match(/^~~/, true)) { // Probably surrounded by space
611
+ if (stream.peek() === ' ') { // Surrounded by spaces, ignore
612
+ return getType(state);
613
+ } else { // Not surrounded by spaces, back up pointer
614
+ stream.backUp(2);
615
+ }
616
+ }
617
+ }
618
+ }
619
+
620
+ if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {
621
+ state.emoji = true;
622
+ if (modeCfg.highlightFormatting) state.formatting = "emoji";
623
+ var retType = getType(state);
624
+ state.emoji = false;
625
+ return retType;
626
+ }
627
+
628
+ if (ch === ' ') {
629
+ if (stream.match(/^ +$/, false)) {
630
+ state.trailingSpace++;
631
+ } else if (state.trailingSpace) {
632
+ state.trailingSpaceNewLine = true;
633
+ }
634
+ }
635
+
636
+ return getType(state);
637
+ }
638
+
639
+ function linkInline(stream, state) {
640
+ var ch = stream.next();
641
+
642
+ if (ch === ">") {
643
+ state.f = state.inline = inlineNormal;
644
+ if (modeCfg.highlightFormatting) state.formatting = "link";
645
+ var type = getType(state);
646
+ if (type) {
647
+ type += " ";
648
+ } else {
649
+ type = "";
650
+ }
651
+ return type + tokenTypes.linkInline;
652
+ }
653
+
654
+ stream.match(/^[^>]+/, true);
655
+
656
+ return tokenTypes.linkInline;
657
+ }
658
+
659
+ function linkHref(stream, state) {
660
+ // Check if space, and return NULL if so (to avoid marking the space)
661
+ if (stream.eatSpace()) {
662
+ return null;
663
+ }
664
+ var ch = stream.next();
665
+ if (ch === '(' || ch === '[') {
666
+ state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");
667
+ if (modeCfg.highlightFormatting) state.formatting = "link-string";
668
+ state.linkHref = true;
669
+ return getType(state);
670
+ }
671
+ return 'error';
672
+ }
673
+
674
+ var linkRE = {
675
+ ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
676
+ "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/
677
+ }
678
+
679
+ function getLinkHrefInside(endChar) {
680
+ return function (stream, state) {
681
+ var ch = stream.next();
682
+
683
+ if (ch === endChar) {
684
+ state.f = state.inline = inlineNormal;
685
+ if (modeCfg.highlightFormatting) state.formatting = "link-string";
686
+ var returnState = getType(state);
687
+ state.linkHref = false;
688
+ return returnState;
689
+ }
690
+
691
+ stream.match(linkRE[endChar])
692
+ state.linkHref = true;
693
+ return getType(state);
694
+ };
695
+ }
696
+
697
+ function footnoteLink(stream, state) {
698
+ if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
699
+ state.f = footnoteLinkInside;
700
+ stream.next(); // Consume [
701
+ if (modeCfg.highlightFormatting) state.formatting = "link";
702
+ state.linkText = true;
703
+ return getType(state);
704
+ }
705
+ return switchInline(stream, state, inlineNormal);
706
+ }
707
+
708
+ function footnoteLinkInside(stream, state) {
709
+ if (stream.match(/^\]:/, true)) {
710
+ state.f = state.inline = footnoteUrl;
711
+ if (modeCfg.highlightFormatting) state.formatting = "link";
712
+ var returnType = getType(state);
713
+ state.linkText = false;
714
+ return returnType;
715
+ }
716
+
717
+ stream.match(/^([^\]\\]|\\.)+/, true);
718
+
719
+ return tokenTypes.linkText;
720
+ }
721
+
722
+ function footnoteUrl(stream, state) {
723
+ // Check if space, and return NULL if so (to avoid marking the space)
724
+ if (stream.eatSpace()) {
725
+ return null;
726
+ }
727
+ // Match URL
728
+ stream.match(/^[^\s]+/, true);
729
+ // Check for link title
730
+ if (stream.peek() === undefined) { // End of line, set flag to check next line
731
+ state.linkTitle = true;
732
+ } else { // More content on line, check if link title
733
+ stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
734
+ }
735
+ state.f = state.inline = inlineNormal;
736
+ return tokenTypes.linkHref + " url";
737
+ }
738
+
739
+ var mode = {
740
+ startState: function () {
741
+ return {
742
+ f: blockNormal,
743
+
744
+ prevLine: { stream: null },
745
+ thisLine: { stream: null },
746
+
747
+ block: blockNormal,
748
+ htmlState: null,
749
+ indentation: 0,
750
+
751
+ inline: inlineNormal,
752
+ text: handleText,
753
+
754
+ formatting: false,
755
+ linkText: false,
756
+ linkHref: false,
757
+ linkTitle: false,
758
+ code: 0,
759
+ em: false,
760
+ strong: false,
761
+ header: 0,
762
+ setext: 0,
763
+ hr: false,
764
+ taskList: false,
765
+ list: false,
766
+ listStack: [],
767
+ quote: 0,
768
+ trailingSpace: 0,
769
+ trailingSpaceNewLine: false,
770
+ strikethrough: false,
771
+ emoji: false,
772
+ fencedEndRE: null
773
+ };
774
+ },
775
+
776
+ copyState: function (s) {
777
+ return {
778
+ f: s.f,
779
+
780
+ prevLine: s.prevLine,
781
+ thisLine: s.thisLine,
782
+
783
+ block: s.block,
784
+ htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
785
+ indentation: s.indentation,
786
+
787
+ localMode: s.localMode,
788
+ localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
789
+
790
+ inline: s.inline,
791
+ text: s.text,
792
+ formatting: false,
793
+ linkText: s.linkText,
794
+ linkTitle: s.linkTitle,
795
+ linkHref: s.linkHref,
796
+ code: s.code,
797
+ em: s.em,
798
+ strong: s.strong,
799
+ strikethrough: s.strikethrough,
800
+ emoji: s.emoji,
801
+ header: s.header,
802
+ setext: s.setext,
803
+ hr: s.hr,
804
+ taskList: s.taskList,
805
+ list: s.list,
806
+ listStack: s.listStack.slice(0),
807
+ quote: s.quote,
808
+ indentedCode: s.indentedCode,
809
+ trailingSpace: s.trailingSpace,
810
+ trailingSpaceNewLine: s.trailingSpaceNewLine,
811
+ md_inside: s.md_inside,
812
+ fencedEndRE: s.fencedEndRE
813
+ };
814
+ },
815
+
816
+ token: function (stream, state) {
817
+
818
+ // Reset state.formatting
819
+ state.formatting = false;
820
+
821
+ if (stream != state.thisLine.stream) {
822
+ state.header = 0;
823
+ state.hr = false;
824
+
825
+ if (stream.match(/^\s*$/, true)) {
826
+ blankLine(state);
827
+ return null;
828
+ }
829
+
830
+ state.prevLine = state.thisLine
831
+ state.thisLine = { stream: stream }
832
+
833
+ // Reset state.taskList
834
+ state.taskList = false;
835
+
836
+ // Reset state.trailingSpace
837
+ state.trailingSpace = 0;
838
+ state.trailingSpaceNewLine = false;
839
+
840
+ if (!state.localState) {
841
+ state.f = state.block;
842
+ if (state.f != htmlBlock) {
843
+ var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;
844
+ state.indentation = indentation;
845
+ state.indentationDiff = null;
846
+ if (indentation > 0) return null;
847
+ }
848
+ }
849
+ }
850
+ return state.f(stream, state);
851
+ },
852
+
853
+ innerMode: function (state) {
854
+ if (state.block == htmlBlock) return { state: state.htmlState, mode: htmlMode };
855
+ if (state.localState) return { state: state.localState, mode: state.localMode };
856
+ return { state: state, mode: mode };
857
+ },
858
+
859
+ indent: function (state, textAfter, line) {
860
+ if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)
861
+ if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)
862
+ return CodeMirror.Pass
863
+ },
864
+
865
+ blankLine: blankLine,
866
+
867
+ getType: getType,
868
+
869
+ blockCommentStart: "<!--",
870
+ blockCommentEnd: "-->",
871
+ closeBrackets: "()[]{}''\"\"``",
872
+ fold: "markdown"
873
+ };
874
+ return mode;
875
+ }, "xml");
876
+
877
+ CodeMirror.defineMIME("text/markdown", "markdown");
878
+
879
+ CodeMirror.defineMIME("text/x-markdown", "markdown");