Skip to content

Commit 3beea43

Browse files
committed
Fix missing content on paragraphs after checkbox
Closes syntax-tree/mdast-util-from-markdown#6.
1 parent def8ab0 commit 3beea43

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

from-markdown.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,38 @@ function exitCheck(token) {
1111
}
1212

1313
function exitParagraphWithTaskListItem(token) {
14-
var node = this.stack[this.stack.length - 1]
1514
var parent = this.stack[this.stack.length - 2]
15+
var node = this.stack[this.stack.length - 1]
16+
var siblings = parent.children
1617
var head = node.children[0]
18+
var index = -1
19+
var firstParaghraph
1720

1821
if (
22+
parent &&
1923
parent.type === 'listItem' &&
2024
typeof parent.checked === 'boolean' &&
2125
head &&
2226
head.type === 'text'
2327
) {
24-
// Must start with a space or a tab.
25-
head.value = head.value.slice(1)
26-
if (head.value.length === 0) {
27-
node.children.shift()
28-
} else {
29-
head.position.start.column++
30-
head.position.start.offset++
31-
node.position.start = Object.assign({}, head.position.start)
28+
while (++index < siblings.length) {
29+
if (siblings[index].type === 'paragraph') {
30+
firstParaghraph = siblings[index]
31+
break
32+
}
33+
}
34+
35+
if (firstParaghraph === node) {
36+
// Must start with a space or a tab.
37+
head.value = head.value.slice(1)
38+
39+
if (head.value.length === 0) {
40+
node.children.shift()
41+
} else {
42+
head.position.start.column++
43+
head.position.start.offset++
44+
node.position.start = Object.assign({}, head.position.start)
45+
}
3246
}
3347
}
3448

test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ test('markdown -> mdast', function (t) {
162162
'should support a text construct after the checkbox'
163163
)
164164

165+
t.deepEqual(
166+
removePosition(
167+
fromMarkdown('* [x] a\n\n b', {
168+
extensions: [syntax],
169+
mdastExtensions: [taskListItem.fromMarkdown]
170+
}),
171+
true
172+
).children[0].children[0],
173+
{
174+
type: 'listItem',
175+
spread: true,
176+
checked: true,
177+
children: [
178+
{
179+
type: 'paragraph',
180+
children: [{type: 'text', value: 'a'}]
181+
},
182+
{
183+
type: 'paragraph',
184+
children: [{type: 'text', value: 'b'}]
185+
}
186+
]
187+
},
188+
'should support further paragraphs after checkboxes'
189+
)
190+
165191
t.end()
166192
})
167193

0 commit comments

Comments
 (0)