@@ -177,9 +177,23 @@ import {stringify as spaces} from 'space-separated-tokens'
177
177
import styleToObject from 'style-to-object'
178
178
import { pointStart } from 'unist-util-position'
179
179
import { VFileMessage } from 'vfile-message'
180
+ import { whitespace } from 'hast-util-whitespace'
180
181
181
182
const own = { } . hasOwnProperty
182
183
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
+
183
197
/**
184
198
* Transform a hast tree to preact, react, solid, svelte, vue, etc.,
185
199
* with an automatic JSX runtime.
@@ -272,14 +286,21 @@ function one(state, node, key) {
272
286
state . schema = schema
273
287
}
274
288
275
- const children = createChildren ( state , node )
289
+ let children = createChildren ( state , node )
276
290
const props = createProperties ( state , node )
291
+ let type = state . Fragment
277
292
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
+ }
279
297
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
+ }
283
304
}
284
305
285
306
props . children = children
0 commit comments