Explorar el Código

optional heading params

Ivan Asmer hace 4 años
padre
commit
0823f2909b
Se han modificado 1 ficheros con 7 adiciones y 4 borrados
  1. 7 4
      index.mjs

+ 7 - 4
index.mjs

@@ -671,11 +671,14 @@ function toReact(ast, React, mapMDToComponents=defaultMapMDToComponents){
     const _ = React.createElement.bind(React)
     const childToReact = child => typeof child === 'string' ?  child  : 
                                                                toReact(child, React, mapMDToComponents)
-    return _(RenderComponent, {node: ast, 
-                                key: Math.random(),
-                               children: ast.children.map(childToReact),
+    const props = {key: Math.random()
+                               children: ast.children.map(childToReact)}
+    if (typeof RenderComponent !== 'string' && RenderComponent !== React.Fragment)
+        Object.assign(props,{node: ast, 
                                title: ast.title && ast.title.map(childToReact),
-                               react: React})
+                               react: React}
+        
+    return _(RenderComponent, props)
 }
 
 export {buildAST, toReact}