diff --git a/src/Lexer.ts b/src/Lexer.ts
index a54910ab8d..89d439dc8c 100644
--- a/src/Lexer.ts
+++ b/src/Lexer.ts
@@ -16,8 +16,9 @@ export class _Lexer {
top: boolean;
};
+ public inlineQueue: { src: string, tokens: Token[] }[];
+
private tokenizer: _Tokenizer;
- private inlineQueue: { src: string, tokens: Token[] }[];
constructor(options?: MarkedOptions) {
// TokenList cannot be created in one go
diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts
index 34674e02da..4f176de664 100644
--- a/src/Tokenizer.ts
+++ b/src/Tokenizer.ts
@@ -380,19 +380,10 @@ export class _Tokenizer {
}
}
- let istask: RegExpExecArray | null = null;
- // Check for task list items
- if (this.options.gfm) {
- istask = this.rules.other.listIsTask.exec(itemContents);
- if (istask) {
- itemContents = itemContents.replace(this.rules.other.listReplaceTask, '');
- }
- }
-
list.items.push({
type: 'list_item',
raw,
- task: !!istask,
+ task: !!this.options.gfm && this.rules.other.listIsTask.test(itemContents),
loose: false,
text: itemContents,
tokens: [],
@@ -417,6 +408,19 @@ export class _Tokenizer {
this.lexer.state.top = false;
item.tokens = this.lexer.blockTokens(item.text, []);
if (item.task) {
+ // Remove checkbox markdown from item tokens
+ item.text = item.text.replace(this.rules.other.listReplaceTask, '');
+ if (item.tokens[0]?.type === 'text' || item.tokens[0]?.type === 'paragraph') {
+ item.tokens[0].raw = item.tokens[0].raw.replace(this.rules.other.listReplaceTask, '');
+ item.tokens[0].text = item.tokens[0].text.replace(this.rules.other.listReplaceTask, '');
+ for (let i = this.lexer.inlineQueue.length - 1; i >= 0; i--) {
+ if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[i].src)) {
+ this.lexer.inlineQueue[i].src = this.lexer.inlineQueue[i].src.replace(this.rules.other.listReplaceTask, '');
+ break;
+ }
+ }
+ }
+
const taskRaw = this.rules.other.listTaskCheckbox.exec(item.raw);
if (taskRaw) {
const checkboxToken: Tokens.Checkbox = {
diff --git a/src/rules.ts b/src/rules.ts
index acd6207396..2f95b80be2 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -46,7 +46,7 @@ export const other = {
blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
listReplaceTabs: /^\t+/,
listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
- listIsTask: /^\[[ xX]\] /,
+ listIsTask: /^\[[ xX]\] +\S/,
listReplaceTask: /^\[[ xX]\] +/,
listTaskCheckbox: /\[[ xX]\]/,
anyLine: /\n.*\n/,
diff --git a/test/specs/new/list_loose_tasks.html b/test/specs/new/list_loose_tasks.html
index f7bc47eb1b..1416f042ef 100644
--- a/test/specs/new/list_loose_tasks.html
+++ b/test/specs/new/list_loose_tasks.html
@@ -6,10 +6,9 @@
Task1
-
-Task2
+
Task2
-
+[ ]
diff --git a/test/specs/new/tasklist_blocks.html b/test/specs/new/tasklist_blocks.html
new file mode 100644
index 0000000000..6a8fb31f36
--- /dev/null
+++ b/test/specs/new/tasklist_blocks.html
@@ -0,0 +1,53 @@
+tight
+
+loose
+
diff --git a/test/specs/new/tasklist_blocks.md b/test/specs/new/tasklist_blocks.md
new file mode 100644
index 0000000000..488a461220
--- /dev/null
+++ b/test/specs/new/tasklist_blocks.md
@@ -0,0 +1,40 @@
+# tight
+
+- [x] # heading
+- [x] - list
+- [x] > blockquote
+- [x] ---
+- [x] ```
+ ```
+- [x] [def]: https://example.com
+- [x]
+ *html*
+
+ *html*
+- [x] | a | b |
+ |---|---|
+ | 1 | 1 |
+
+# loose
+
+- [x] # heading
+
+- [x] - list
+
+- [x] > blockquote
+
+- [x] ---
+
+- [x] ```
+ ```
+
+- [x] [def]: https://example.com
+
+- [x]
+ *html*
+
+ *html*
+
+- [x] | a | b |
+ |---|---|
+ | 1 | 1 |