Skip to content

Commit c3dc5ee

Browse files
committed
Fix to not crash on empty text nodes
Closes GH-494.
1 parent ce56761 commit c3dc5ee

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/renderers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ module.exports = {
4040
}
4141

4242
function TextRenderer(props) {
43+
const children = props.children || ''
4344
/* istanbul ignore next - `span` is a fallback for old React. */
44-
return supportsStringRender ? props.children : createElement('span', null, props.children)
45+
return supportsStringRender ? children : createElement('span', null, children)
4546
}
4647

4748
function Root(props) {

test/react-markdown.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,10 @@ test('should pass `node` as prop to all non-tag/non-fragment renderers', () => {
886886
const component = renderer.create(<Markdown renderers={{heading}} children={input} />)
887887
expect(component.toJSON()).toBe("So, headers... they're cool")
888888
})
889+
890+
test('should support formatting at the start of a GFM tasklist (GH-494)', () => {
891+
const input = '- [ ] *a*'
892+
const actual = renderHTML(<Markdown children={input} plugins={[gfm]} />)
893+
const expected = '<ul><li><input type="checkbox" readonly=""/><em>a</em></li></ul>'
894+
expect(actual).toEqual(expected)
895+
})

0 commit comments

Comments
 (0)