summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/components/RenderNode.astro
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/markdoc/components/RenderNode.astro')
-rw-r--r--packages/integrations/markdoc/components/RenderNode.astro30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/integrations/markdoc/components/RenderNode.astro b/packages/integrations/markdoc/components/RenderNode.astro
new file mode 100644
index 000000000..a683cd983
--- /dev/null
+++ b/packages/integrations/markdoc/components/RenderNode.astro
@@ -0,0 +1,30 @@
+---
+import stringifyAttributes from 'stringify-attributes';
+import type { AstroNode } from './astroNode';
+
+type Props = {
+ node: AstroNode;
+};
+
+const Node = (Astro.props as Props).node;
+---
+
+{
+ typeof Node === 'string' ? (
+ <Fragment set:text={Node} />
+ ) : 'component' in Node ? (
+ <Node.component {...Node.props}>
+ {Node.children.map((child) => (
+ <Astro.self node={child} />
+ ))}
+ </Node.component>
+ ) : (
+ <Fragment>
+ <Fragment set:html={`<${Node.tag} ${stringifyAttributes(Node.attributes)}>`} />
+ {Node.children.map((child) => (
+ <Astro.self node={child} />
+ ))}
+ <Fragment set:html={`</${Node.tag}>`} />
+ </Fragment>
+ )
+}