safe-mdx 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/safe-mdx.tsx CHANGED
@@ -105,7 +105,9 @@ export class MdastToJsx {
105
105
  ?.flatMap((child) => this.mdastTransformer(child))
106
106
  .filter(Boolean)
107
107
  if (Array.isArray(res)) {
108
- if (res.length === 1) {
108
+ if (!res.length) {
109
+ return null
110
+ } else if (res.length === 1) {
109
111
  return res[0]
110
112
  } else {
111
113
  return res.map((x, i) =>
@@ -120,7 +122,9 @@ export class MdastToJsx {
120
122
  ?.flatMap((child, i) => this.jsxTransformer(child))
121
123
  .filter(Boolean)
122
124
  if (Array.isArray(res)) {
123
- if (res.length === 1) {
125
+ if (!res.length) {
126
+ return null
127
+ } else if (res.length === 1) {
124
128
  return res[0]
125
129
  } else {
126
130
  return res.map((x, i) =>
@@ -319,9 +323,14 @@ export class MdastToJsx {
319
323
  return <Fragment>{this.mapMdastChildren(node)}</Fragment>
320
324
  }
321
325
  case 'table': {
322
- const align = node.align
326
+ const [head, ...body] = React.Children.toArray(
327
+ this.mapMdastChildren(node),
328
+ )
323
329
  return (
324
- <this.c.table>{this.mapMdastChildren(node)}</this.c.table>
330
+ <this.c.table>
331
+ {head && <this.c.thead>{head}</this.c.thead>}
332
+ {!!body?.length && <this.c.tbody>{body}</this.c.tbody>}
333
+ </this.c.table>
325
334
  )
326
335
  }
327
336
  case 'tableRow': {