-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathlist-item.js
56 lines (44 loc) · 1.13 KB
/
list-item.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
module.exports = listItem
var u = require('unist-builder')
var wrap = require('../wrap')
var all = require('../all')
/* Transform a list-item. */
function listItem(h, node, parent) {
var children = node.children
var head = children[0]
var props = {}
var single = false
var result
var container
if (
(!parent || !parent.loose) &&
children.length === 1 &&
head.type === 'paragraph'
) {
single = true
}
result = all(h, single ? head : node)
if (typeof node.checked === 'boolean') {
if (!single && (!head || head.type !== 'paragraph')) {
result.unshift(h(null, 'p', []))
}
container = single ? result : result[0].children
if (container.length !== 0) {
container.unshift(u('text', ' '))
}
container.unshift(
h(null, 'input', {
type: 'checkbox',
checked: node.checked,
disabled: true
})
)
/* According to github-markdown-css, this class hides bullet. */
props.className = ['task-list-item']
}
if (!single && result.length !== 0) {
result = wrap(result, true)
}
return h(node, 'li', props, result)
}