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/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/dist/safe-mdx.d.ts.map +1 -1
- package/dist/safe-mdx.js +51 -78
- package/dist/safe-mdx.js.map +1 -1
- package/dist/safe-mdx.test.js +450 -175
- package/dist/safe-mdx.test.js.map +1 -1
- package/package.json +16 -4
- package/src/safe-mdx.test.tsx +434 -148
- package/src/safe-mdx.tsx +13 -4
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
|
|
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
|
|
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
|
|
326
|
+
const [head, ...body] = React.Children.toArray(
|
|
327
|
+
this.mapMdastChildren(node),
|
|
328
|
+
)
|
|
323
329
|
return (
|
|
324
|
-
<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': {
|