Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
top: boolean;
};

public inlineQueue: { src: string, tokens: Token[] }[];

private tokenizer: _Tokenizer<ParserOutput, RendererOutput>;
private inlineQueue: { src: string, tokens: Token[] }[];

constructor(options?: MarkedOptions<ParserOutput, RendererOutput>) {
// TokenList cannot be created in one go
Expand Down
24 changes: 14 additions & 10 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,10 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
}
}

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: [],
Expand All @@ -417,6 +408,19 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
Expand Down
5 changes: 2 additions & 3 deletions test/specs/new/list_loose_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<p><input type="checkbox" checked="" disabled=""> Task1</p>
</li>
<li>
<p><input type="checkbox" disabled=""></p>
<pre>Task2</pre>
<p><input type="checkbox" disabled=""> <pre>Task2</pre></p>
</li>
<li>
<p><input type="checkbox" disabled=""></p>
<p>[ ]</p>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These tests were wrong before. They match GitHub now

</li>
</ul>
53 changes: 53 additions & 0 deletions test/specs/new/tasklist_blocks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<h1>tight</h1>
<ul>
<li><input checked="" disabled="" type="checkbox"> # heading</li>
<li><input checked="" disabled="" type="checkbox"> - list</li>
<li><input checked="" disabled="" type="checkbox"> &gt; blockquote</li>
<li><input checked="" disabled="" type="checkbox"> ---</li>
<li><input checked="" disabled="" type="checkbox"> ```
<pre><code></code></pre>
</li>
<li><input checked="" disabled="" type="checkbox"> [def]: <a href="https://example.com">https://example.com</a></li>
<li><input checked="" disabled="" type="checkbox"> <div>
<em>html</em>
</div>
*html*
</li>
<li><input checked="" disabled="" type="checkbox"> | a | b |
|---|---|
| 1 | 1 |</li>
</ul>
<h1>loose</h1>
<ul>
<li>
<p><input checked="" disabled="" type="checkbox"> # heading</p>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> - list</p>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> &gt; blockquote</p>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> ---</p>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> ```</p>
<pre><code>
</code></pre>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> [def]: <a href="https://example.com">https://example.com</a></p>
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> <div>
<em>html</em></p>
</div>
*html*
</li>
<li>
<p><input checked="" disabled="" type="checkbox"> | a | b |
|---|---|
| 1 | 1 |</p>
</li>
</ul>
40 changes: 40 additions & 0 deletions test/specs/new/tasklist_blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# tight

- [x] # heading
- [x] - list
- [x] > blockquote
- [x] ---
- [x] ```
```
- [x] [def]: https://example.com
- [x] <div>
*html*
</div>
*html*
- [x] | a | b |
|---|---|
| 1 | 1 |

# loose

- [x] # heading

- [x] - list

- [x] > blockquote

- [x] ---

- [x] ```
```

- [x] [def]: https://example.com

- [x] <div>
*html*
</div>
*html*

- [x] | a | b |
|---|---|
| 1 | 1 |