2 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
3 mod(require("../../lib/codemirror"));
4 else if (typeof define
== "function" && define
.amd
) // AMD
5 define(["../../lib/codemirror"], mod
);
6 else // Plain browser env
8 })(function(CodeMirror
) {
11 var listRE
= /^(\s*)([*+-]|(\d+)\.)(\s*)/,
12 unorderedBullets
= "*+-";
14 CodeMirror
.commands
.newlineAndIndentContinueMarkdownList = function(cm
) {
15 if (cm
.getOption("disableInput")) return CodeMirror
.Pass
;
16 var ranges
= cm
.listSelections(), replacements
= [];
17 for (var i
= 0; i
< ranges
.length
; i
++) {
18 var pos
= ranges
[i
].head
, match
;
19 var inList
= cm
.getStateAfter(pos
.line
).list
!== false;
21 if (!ranges
[i
].empty() || !inList
|| !(match
= cm
.getLine(pos
.line
).match(listRE
))) {
22 cm
.execCommand("newlineAndIndent");
25 var indent
= match
[1], after
= match
[4];
26 var bullet
= unorderedBullets
.indexOf(match
[2]) >= 0
28 : (parseInt(match
[3], 10) + 1) + ".";
30 replacements
[i
] = "\n" + indent
+ bullet
+ after
;
33 cm
.replaceSelections(replacements
);