Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50665 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)\.)(\s*)/,
15
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)\.)(\s*)$/,
16
unorderedListRE = /[*+-]\s/;
17
18
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
19
if (cm.getOption("disableInput")) return CodeMirror.Pass;
20
var ranges = cm.listSelections(), replacements = [];
21
for (var i = 0; i < ranges.length; i++) {
22
var pos = ranges[i].head, match;
23
var eolState = cm.getStateAfter(pos.line);
24
var inList = eolState.list !== false;
25
var inQuote = eolState.quote !== false;
26
27
if (!ranges[i].empty() || (!inList && !inQuote) || !(match = cm.getLine(pos.line).match(listRE))) {
28
cm.execCommand("newlineAndIndent");
29
return;
30
}
31
if (cm.getLine(pos.line).match(emptyListRE)) {
32
cm.replaceRange("", {
33
line: pos.line, ch: 0
34
}, {
35
line: pos.line, ch: pos.ch + 1
36
});
37
replacements[i] = "\n";
38
39
} else {
40
var indent = match[1], after = match[4];
41
var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0
42
? match[2]
43
: (parseInt(match[3], 10) + 1) + ".";
44
45
replacements[i] = "\n" + indent + bullet + after;
46
}
47
}
48
49
cm.replaceSelections(replacements);
50
};
51
});
52
53