diff --git a/src/Tokenizer.js b/src/Tokenizer.js index 2efb3b7ea7..b2a372ed4f 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -225,11 +225,13 @@ export class Tokenizer { } if (!endEarly) { - const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])`); + const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`); // Check if following lines should be included in List Item + let prevLine = line; while (src) { rawLine = src.split('\n', 1)[0]; + prevLine = line; line = rawLine; // Re-align to follow commonmark nesting rules @@ -237,6 +239,18 @@ export class Tokenizer { line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' '); } + if (this.rules.block.hr.test(line)) { + // End list if bullet was actually HR (possibly move into itemRegex?) + // make sure it is not a setext heading, which takes precedence + const twoLines = [prevLine, line].join('\n'); + const matchLheadingPattern = this.rules.block.lheading.test(twoLines); + const lineIdentIsLargerThanPrev = line.search(/[^ ]/) >= indent; + const isNextLineSetextHeading = matchLheadingPattern && lineIdentIsLargerThanPrev; + if (!isNextLineSetextHeading) { + break; + } + } + // End list item if found start of new bullet if (nextBulletRegex.test(line)) { break;