Skip to content

Commit

Permalink
fix: list item bullet without whitespace (#2431)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangxyz committed May 2, 2022
1 parent 6efa77e commit 9c10b4d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Tokenizer.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -279,7 +284,7 @@ export class Tokenizer {

list.items.push({
type: 'list_item',
raw: raw,
raw,
task: !!istask,
checked: ischecked,
loose: false,
Expand Down
24 changes: 24 additions & 0 deletions test/specs/new/list_item_unindented_asterisk.html
@@ -0,0 +1,24 @@
<h2>*list</h2>
<ul>
<li>list1
*Not list(without space)</li>
<li>list2</li>
</ul>
<h2>+list</h2>
<ul>
<li>list1
+Not list(without space)</li>
<li>list2</li>
</ul>
<h2>-list</h2>
<ul>
<li>list1
-Not list(without space)</li>
<li>list2</li>
</ul>
<h2>number(1.)list</h2>
<ol>
<li>list
1.Notlist(without space)</li>
<li>list</li>
</ol>
25 changes: 25 additions & 0 deletions 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

1 comment on commit 9c10b4d

@vercel
Copy link

@vercel vercel bot commented on 9c10b4d May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.