From 9c10b4d68f43697d9e2b1c30356765ff4bdd7b9d Mon Sep 17 00:00:00 2001 From: "Kim, Jang-hwan" Date: Mon, 2 May 2022 15:12:30 +0900 Subject: [PATCH] fix: list item bullet without whitespace (#2431) --- src/Tokenizer.js | 27 +++++++++++-------- .../new/list_item_unindented_asterisk.html | 24 +++++++++++++++++ .../new/list_item_unindented_asterisk.md | 25 +++++++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 test/specs/new/list_item_unindented_asterisk.html create mode 100644 test/specs/new/list_item_unindented_asterisk.md diff --git a/src/Tokenizer.js b/src/Tokenizer.js index 0eec752cc3..755a62d285 100644 --- a/src/Tokenizer.js +++ b/src/Tokenizer.js @@ -23,15 +23,14 @@ function outputLink(cap, link, raw, lexer) { }; lexer.state.inLink = false; return token; - } else { - return { - type: 'image', - raw, - href, - title, - text: escape(text) - }; } + return { + type: 'image', + raw, + href, + title, + text: escape(text) + }; } function indentCodeCompensation(raw, text) { @@ -130,7 +129,7 @@ export class Tokenizer { type: 'heading', raw: cap[0], depth: cap[1].length, - text: text, + text, tokens: [] }; this.lexer.inline(token.text, token.tokens); @@ -225,7 +224,8 @@ 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|$))`); + const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`); // Check if following lines should be included in List Item while (src) { @@ -242,6 +242,11 @@ export class Tokenizer { break; } + // Horizontal rule found + if (hrRegex.test(src)) { + break; + } + if (line.search(/[^ ]/) >= indent || !line.trim()) { // Dedent if possible itemContents += '\n' + line.slice(indent); } else if (!blankLine) { // Until blank line, item doesn't need indentation @@ -279,7 +284,7 @@ export class Tokenizer { list.items.push({ type: 'list_item', - raw: raw, + raw, task: !!istask, checked: ischecked, loose: false, diff --git a/test/specs/new/list_item_unindented_asterisk.html b/test/specs/new/list_item_unindented_asterisk.html new file mode 100644 index 0000000000..6dfea000d7 --- /dev/null +++ b/test/specs/new/list_item_unindented_asterisk.html @@ -0,0 +1,24 @@ +

*list

+ +

+list

+ +

-list

+ +

number(1.)list

+
    +
  1. list + 1.Notlist(without space)
  2. +
  3. list
  4. +
diff --git a/test/specs/new/list_item_unindented_asterisk.md b/test/specs/new/list_item_unindented_asterisk.md new file mode 100644 index 0000000000..330ebe9b54 --- /dev/null +++ b/test/specs/new/list_item_unindented_asterisk.md @@ -0,0 +1,25 @@ +--- +headerIds: false +--- +## *list + +* list1 +*Not list(without space) +* list2 + +## +list + ++ list1 ++Not list(without space) ++ list2 + +## -list + +- list1 +-Not list(without space) +- list2 + +## number(1.)list +1. list +1.Notlist(without space) +1. list