Skip to content

Commit a7c26fc

Browse files
committed
Remove warning on whitespace in tables
Related to: remarkjs/react-markdown-576
1 parent 748a9d3 commit a7c26fc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/ast-to-react.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
import React from 'react'
104104
import ReactIs from 'react-is'
105+
import {whitespace} from 'hast-util-whitespace'
105106
import {svg, find, hastToReact} from 'property-information'
106107
import {stringify as spaces} from 'space-separated-tokens'
107108
import {stringify as commas} from 'comma-separated-tokens'
@@ -130,12 +131,17 @@ export function childrenToReact(context, node) {
130131
if (child.type === 'element') {
131132
children.push(toReact(context, child, childIndex, node))
132133
} else if (child.type === 'text') {
133-
// React does not permit whitespace text elements as children of table:
134-
// cf. https://github.com/remarkjs/react-markdown/issues/576
134+
// Currently, a warning is triggered by react for *any* white space in
135+
// tables.
136+
// So we drop it.
137+
// See: <https://github.com/facebook/react/pull/7081>.
138+
// See: <https://github.com/facebook/react/pull/7515>.
139+
// See: <https://github.com/remarkjs/remark-react/issues/64>.
140+
// See: <https://github.com/remarkjs/react-markdown/issues/576>.
135141
if (
136142
node.type !== 'element' ||
137143
!tableElements.has(node.tagName) ||
138-
child.value !== '\n'
144+
!whitespace(child)
139145
) {
140146
children.push(child.value)
141147
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@types/hast": "^2.0.0",
8383
"@types/unist": "^2.0.0",
8484
"comma-separated-tokens": "^2.0.0",
85+
"hast-util-whitespace": "^2.0.0",
8586
"prop-types": "^15.0.0",
8687
"property-information": "^6.0.0",
8788
"react-is": "^17.0.0",

0 commit comments

Comments
 (0)