diff options
author | 2025-06-05 14:25:23 +0000 | |
---|---|---|
committer | 2025-06-05 14:25:23 +0000 | |
commit | e586d7d704d475afe3373a1de6ae20d504f79d6d (patch) | |
tree | 7e3fa24807cebd48a86bd40f866d792181191ee9 /packages/integrations/markdoc/components/Renderer.astro | |
download | astro-latest.tar.gz astro-latest.tar.zst astro-latest.zip |
Sync from a8e1c0a7402940e0fc5beef669522b315052df1blatest
Diffstat (limited to 'packages/integrations/markdoc/components/Renderer.astro')
-rw-r--r-- | packages/integrations/markdoc/components/Renderer.astro | 23 |
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} /> |