|
1 | 1 | /**
|
2 |
| - * @typedef {import('unist').Node} UnistNode |
3 |
| - * @typedef {import('hast').Parent} Parent |
4 | 2 | * @typedef {import('hast').Root} Root
|
5 | 3 | * @typedef {import('hast').Element} Element
|
6 | 4 | * @typedef {import('hast').Text} Text
|
7 | 5 | * @typedef {import('hast').Comment} Comment
|
8 | 6 | * @typedef {import('hast').Properties} Properties
|
9 |
| - * @typedef {Root['children'][number]|Root} Node |
| 7 | + * @typedef {import('hast').Content} Content |
| 8 | + * @typedef {Root|Content} Node |
| 9 | + * @typedef {Extract<Node, import('unist').Parent>} Parent |
10 | 10 | * @typedef {import('estree-jsx').Node} EstreeNode
|
11 | 11 | * @typedef {import('estree-jsx').Program} EstreeProgram
|
12 | 12 | * @typedef {import('estree-jsx').JSXExpressionContainer} EstreeJsxExpressionContainer
|
@@ -71,6 +71,15 @@ import {zwitch} from 'zwitch'
|
71 | 71 | const toReact = /** @type {Record<string, string>} */ (hastToReact)
|
72 | 72 |
|
73 | 73 | const own = {}.hasOwnProperty
|
| 74 | +const tableElements = new Set([ |
| 75 | + 'table', |
| 76 | + 'thead', |
| 77 | + 'tbody', |
| 78 | + 'tfoot', |
| 79 | + 'tr', |
| 80 | + 'th', |
| 81 | + 'td' |
| 82 | +]) |
74 | 83 |
|
75 | 84 | /**
|
76 | 85 | * @param {Node|MDXJsxAttributeValueExpression|MDXJsxAttribute|MDXJsxExpressionAttribute|MDXJsxFlowElement|MDXJsxTextElement|MDXFlowExpression|MDXTextExpression} tree
|
@@ -184,6 +193,7 @@ function element(node, context) {
|
184 | 193 | }
|
185 | 194 |
|
186 | 195 | const children = all(node, context)
|
| 196 | + |
187 | 197 | /** @type {Array<EstreeJsxAttribute|EstreeJsxSpreadAttribute>} */
|
188 | 198 | const attributes = []
|
189 | 199 | /** @type {string} */
|
@@ -552,9 +562,25 @@ function all(parent, context) {
|
552 | 562 | let index = -1
|
553 | 563 | /** @type {Array.<EstreeJsxChild>} */
|
554 | 564 | const results = []
|
| 565 | + // Currently, a warning is triggered by react for *any* white space in |
| 566 | + // tables. |
| 567 | + // So we remove the pretty lines for now. |
| 568 | + // See: <https://github.com/facebook/react/pull/7081>. |
| 569 | + // See: <https://github.com/facebook/react/pull/7515>. |
| 570 | + // See: <https://github.com/remarkjs/remark-react/issues/64>. |
| 571 | + const ignoreLineBreak = |
| 572 | + context.schema.space === 'html' && |
| 573 | + parent.type === 'element' && |
| 574 | + tableElements.has(parent.tagName.toLowerCase()) |
555 | 575 |
|
556 | 576 | while (++index < children.length) {
|
557 |
| - const result = context.handle(children[index], context) |
| 577 | + const child = children[index] |
| 578 | + |
| 579 | + if (ignoreLineBreak && child.type === 'text' && child.value === '\n') { |
| 580 | + continue |
| 581 | + } |
| 582 | + |
| 583 | + const result = context.handle(child, context) |
558 | 584 |
|
559 | 585 | if (Array.isArray(result)) {
|
560 | 586 | results.push(...result)
|
|
0 commit comments