@@ -177,9 +177,23 @@ import {stringify as spaces} from 'space-separated-tokens'
177177import styleToObject from 'style-to-object'
178178import { pointStart } from 'unist-util-position'
179179import { VFileMessage } from 'vfile-message'
180+ import { whitespace } from 'hast-util-whitespace'
180181
181182const own = { } . hasOwnProperty
182183
184+ // `react-dom` triggers a warning for *any* white space in tables.
185+ // To follow GFM, `mdast-util-to-hast` injects line endings between elements.
186+ // Other tools might do so too, but they don’t do here, so we remove all of
187+ // that.
188+
189+ // See: <https://github.com/facebook/react/pull/7081>.
190+ // See: <https://github.com/facebook/react/pull/7515>.
191+ // See: <https://github.com/remarkjs/remark-react/issues/64>.
192+ // See: <https://github.com/rehypejs/rehype-react/pull/29>.
193+ // See: <https://github.com/rehypejs/rehype-react/pull/32>.
194+ // See: <https://github.com/rehypejs/rehype-react/pull/45>.
195+ const tableElements = new Set ( [ 'table' , 'thead' , 'tbody' , 'tfoot' , 'tr' ] )
196+
183197/**
184198 * Transform a hast tree to preact, react, solid, svelte, vue, etc.,
185199 * with an automatic JSX runtime.
@@ -272,14 +286,21 @@ function one(state, node, key) {
272286 state . schema = schema
273287 }
274288
275- const children = createChildren ( state , node )
289+ let children = createChildren ( state , node )
276290 const props = createProperties ( state , node )
291+ let type = state . Fragment
277292
278- let type = node . type === 'root' ? state . Fragment : node . tagName
293+ if ( node . type === 'element' ) {
294+ if ( tableElements . has ( node . tagName ) ) {
295+ children = children . filter ( ( child ) => ! whitespace ( child ) )
296+ }
279297
280- if ( typeof type === 'string' && own . call ( state . components , type ) ) {
281- const key = /** @type {keyof JSX.IntrinsicElements } */ ( type )
282- type = state . components [ key ]
298+ if ( own . call ( state . components , node . tagName ) ) {
299+ const key = /** @type {keyof JSX.IntrinsicElements } */ ( node . tagName )
300+ type = state . components [ key ]
301+ } else {
302+ type = node . tagName
303+ }
283304 }
284305
285306 props . children = children
0 commit comments