-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathtaskListItem.js
More file actions
35 lines (32 loc) · 1.11 KB
/
taskListItem.js
File metadata and controls
35 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export const taskListItemCompiler = ({ renderer }) =>
(renderer.listitem = function (item) {
let text = '';
if (item.task) {
const checkbox = this.checkbox?.({ checked: !!item.checked });
if (item.loose) {
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
if (
item.tokens[0].tokens &&
item.tokens[0].tokens.length > 0 &&
item.tokens[0].tokens[0].type === 'text'
) {
item.tokens[0].tokens[0].text =
checkbox + ' ' + item.tokens[0].tokens[0].text;
}
} else {
item.tokens.unshift({
type: 'text',
raw: checkbox + ' ',
text: checkbox + ' ',
});
}
}
}
text += this.parser?.parse(item.tokens, !!item.loose);
const isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text);
const html = isTaskItem
? /* html */ `<li class="task-list-item"><label>${text}</label></li>`
: /* html */ `<li>${text}</li>`;
return html;
});