Skip to content

Commit ec141d0

Browse files
committed
Fix empty text node for emphasis after task
Related to: remarkjs/react-markdown#494.
1 parent 3a33370 commit ec141d0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

from-markdown.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ function exitParagraphWithTaskListItem(token) {
2323
) {
2424
// Must start with a space or a tab.
2525
head.value = head.value.slice(1)
26-
head.position.start.column++
27-
head.position.start.offset++
28-
node.position.start = Object.assign({}, head.position.start)
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)
32+
}
2933
}
3034

3135
this.exit(token)

test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ test('markdown -> mdast', function (t) {
140140
'should not support a task list item when not in a list item'
141141
)
142142

143+
t.deepEqual(
144+
removePosition(
145+
fromMarkdown('* [x] *b*', {
146+
extensions: [syntax],
147+
mdastExtensions: [taskListItem.fromMarkdown]
148+
}),
149+
true
150+
).children[0].children[0],
151+
{
152+
type: 'listItem',
153+
spread: false,
154+
checked: true,
155+
children: [
156+
{
157+
type: 'paragraph',
158+
children: [{type: 'emphasis', children: [{type: 'text', value: 'b'}]}]
159+
}
160+
]
161+
},
162+
'should support a text construct after the checkbox'
163+
)
164+
143165
t.end()
144166
})
145167

0 commit comments

Comments
 (0)