mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 13:53:11 +00:00
renderer - Handle fragment same way as array
This commit is contained in:
+8
-1
@@ -1,5 +1,5 @@
|
|||||||
import { root, text } from 'mdast-builder';
|
import { root, text } from 'mdast-builder';
|
||||||
import { Children as ReactChildren } from 'react';
|
import { Children as ReactChildren, Fragment } from 'react';
|
||||||
import * as stringify from 'remark-stringify';
|
import * as stringify from 'remark-stringify';
|
||||||
import * as unified from 'unified';
|
import * as unified from 'unified';
|
||||||
// tslint:disable-next-line: no-implicit-dependencies
|
// tslint:disable-next-line: no-implicit-dependencies
|
||||||
@@ -36,6 +36,13 @@ function render(
|
|||||||
// Handle (render) Fragment nodes or arrays
|
// Handle (render) Fragment nodes or arrays
|
||||||
|
|
||||||
node.forEach(fragmentEle => render(fragmentEle, parentASTNodeMod));
|
node.forEach(fragmentEle => render(fragmentEle, parentASTNodeMod));
|
||||||
|
} else if (node.type === Fragment) {
|
||||||
|
const childrenArray = ReactChildren.toArray(
|
||||||
|
node.props.children
|
||||||
|
) as ReactElementSubsetWithPrimitive[];
|
||||||
|
|
||||||
|
// Render processed array of children
|
||||||
|
render(childrenArray, parentASTNodeMod);
|
||||||
} else {
|
} else {
|
||||||
const { props, type: elementType } = node;
|
const { props, type: elementType } = node;
|
||||||
let processChildren = true;
|
let processChildren = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user