summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/components/Renderer.astro
blob: 4b0dbb3a09fab252282247e1d4da7ef7c1213962 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---
//! astro-head-inject
import type { Config } 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);
const content = Markdoc.transform(ast, config);
---

{
	Array.isArray(content) ? (
		content.map(async (c) => <ComponentNode treeNode={await createTreeNode(c)} />)
	) : (
		<ComponentNode treeNode={await createTreeNode(content)} />
	)
}