summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/components/RenderNode.astro
blob: a683cd9839e507a2d0f73748df7f20059ead9296 (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
25
26
27
28
29
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>
	)
}