Skip to content

Commit b47ee05

Browse files
committed
Fix non-paragraph as single child in list-items
Closes remarkjs/remark#270.
1 parent 710cfc5 commit b47ee05

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/handlers/list-item.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ var all = require('../all');
1010
function listItem(h, node, parent) {
1111
var children = node.children;
1212
var head = children[0];
13-
var single = (!parent || !parent.loose) && head && head.children && children.length === 1;
14-
var result = all(h, single ? head : node);
15-
var container;
1613
var props = {};
14+
var single = false;
15+
var result;
16+
var container;
17+
18+
if ((!parent || !parent.loose) && children.length === 1 && head.type === 'paragraph') {
19+
single = true;
20+
}
21+
22+
result = all(h, single ? head : node);
1723

1824
if (typeof node.checked === 'boolean') {
1925
if (!single && (!head || head.type !== 'paragraph')) {

test/list-item.js

+24
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,29 @@ test('ListItem', function (t) {
128128
'should support checkboxes in `listItem`s without children'
129129
);
130130

131+
t.deepEqual(
132+
to(u('listItem', [
133+
u('list', {ordered: false}, [
134+
u('listItem', [
135+
u('paragraph', [
136+
u('text', 'Alpha')
137+
])
138+
])
139+
])
140+
])),
141+
u('element', {tagName: 'li', properties: {}}, [
142+
u('text', '\n'),
143+
u('element', {tagName: 'ul', properties: {}}, [
144+
u('text', '\n'),
145+
u('element', {tagName: 'li', properties: {}}, [
146+
u('text', 'Alpha')
147+
]),
148+
u('text', '\n')
149+
]),
150+
u('text', '\n')
151+
]),
152+
'should support lists in `listItem`s'
153+
);
154+
131155
t.end();
132156
});

0 commit comments

Comments
 (0)