From 736726805d5b37ad6443c677459468e883f00626 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sun, 22 Dec 2019 19:53:11 +0530 Subject: [PATCH] renderer - Handle fragment same way as array --- src/renderer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/renderer.ts b/src/renderer.ts index 6f806a7..2af1401 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -1,5 +1,5 @@ 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 unified from 'unified'; // tslint:disable-next-line: no-implicit-dependencies @@ -36,6 +36,13 @@ function render( // Handle (render) Fragment nodes or arrays 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 { const { props, type: elementType } = node; let processChildren = true;