Skip to content

Commit

Permalink
Remove warning on whitespace in tables
Browse files Browse the repository at this point in the history
Related to: remarkjs/react-markdown-576
  • Loading branch information
wooorm committed Oct 21, 2021
1 parent 748a9d3 commit a7c26fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/ast-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

import React from 'react'
import ReactIs from 'react-is'
import {whitespace} from 'hast-util-whitespace'
import {svg, find, hastToReact} from 'property-information'
import {stringify as spaces} from 'space-separated-tokens'
import {stringify as commas} from 'comma-separated-tokens'
Expand Down Expand Up @@ -130,12 +131,17 @@ export function childrenToReact(context, node) {
if (child.type === 'element') {
children.push(toReact(context, child, childIndex, node))
} else if (child.type === 'text') {
// React does not permit whitespace text elements as children of table:
// cf. https://github.com/remarkjs/react-markdown/issues/576
// Currently, a warning is triggered by react for *any* white space in
// tables.
// So we drop it.
// See: <https://github.com/facebook/react/pull/7081>.
// See: <https://github.com/facebook/react/pull/7515>.
// See: <https://github.com/remarkjs/remark-react/issues/64>.
// See: <https://github.com/remarkjs/react-markdown/issues/576>.
if (
node.type !== 'element' ||
!tableElements.has(node.tagName) ||
child.value !== '\n'
!whitespace(child)
) {
children.push(child.value)
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@types/hast": "^2.0.0",
"@types/unist": "^2.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-whitespace": "^2.0.0",
"prop-types": "^15.0.0",
"property-information": "^6.0.0",
"react-is": "^17.0.0",
Expand Down

0 comments on commit a7c26fc

Please sign in to comment.