Skip to content

Commit 8ecbdc5

Browse files
committed
[markdown mode] Allow lists without a blank line above
As per CommonMark (conflicting with markdown.pl, but never mind markdown.pl) Closes codemirror#4395
1 parent 69669e4 commit 8ecbdc5

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

mode/markdown/markdown.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
8383
}
8484

8585
var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
86-
, ulRE = /^[*\-+]\s+/
87-
, olRE = /^[0-9]+([.)])\s+/
88-
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
86+
, listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/
87+
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow listRE
8988
, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
9089
, setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
9190
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/
@@ -189,14 +188,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
189188
} else if (stream.match(hrRE, true)) {
190189
state.hr = true;
191190
return tokenTypes.hr;
192-
} else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
193-
var listType = null;
194-
if (stream.match(ulRE, true)) {
195-
listType = 'ul';
196-
} else {
197-
stream.match(olRE, true);
198-
listType = 'ol';
199-
}
191+
} else if (match = stream.match(listRE)) {
192+
var listType = match[1] ? "ol" : "ul";
200193
state.indentation = stream.column() + stream.current().length;
201194
state.list = true;
202195

mode/markdown/test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,10 @@
357357
"[variable-2 1. foo]",
358358
"[variable-2 2. bar]");
359359

360-
// Lists require a preceding blank line (per Dingus)
361-
MT("listBogus",
360+
MT("listFromParagraph",
362361
"foo",
363-
"1. bar",
364-
"2. hello");
362+
"[variable-2 1. bar]",
363+
"[variable-2 2. hello]");
365364

366365
// List after hr
367366
MT("listAfterHr",

0 commit comments

Comments
 (0)