aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/components/Renderer.astro
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/markdoc/components/Renderer.astro')
-rw-r--r--packages/integrations/markdoc/components/Renderer.astro23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/integrations/markdoc/components/Renderer.astro b/packages/integrations/markdoc/components/Renderer.astro
new file mode 100644
index 000000000..270604091
--- /dev/null
+++ b/packages/integrations/markdoc/components/Renderer.astro
@@ -0,0 +1,23 @@
+---
+//! astro-head-inject
+import type { Config, RenderableTreeNodes } from '@markdoc/markdoc';
+import Markdoc from '@markdoc/markdoc';
+import { ComponentNode, createTreeNode } from './TreeNode.js';
+
+type Props = {
+ config: Config;
+ stringifiedAst: string;
+};
+
+const { stringifiedAst, config } = Astro.props as Props;
+
+const ast = Markdoc.Ast.fromJSON(stringifiedAst);
+// The AST may be an array, and `transform` has overloads for arrays and non-array cases,
+// However TypeScript seems to struggle to combine both overloads into a single signature.
+// Also, `transform` returns a promise here but the types don't reflect that.
+// @ts-expect-error
+const content = (await Markdoc.transform(ast, config)) as RenderableTreeNodes;
+const treeNode = await createTreeNode(content);
+---
+
+<ComponentNode treeNode={treeNode} />