0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-13 22:11:20 -05:00
astro/packages/integrations/markdoc/components/Renderer.astro

23 lines
817 B
Text

---
//! 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} />