node.astro
1.03 KB
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
31
32
33
34
35
36
37
---
import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import type { NodeType } from 'ultrahtml'
import Children from './children.astro'
interface Props {
html?: string,
debug?: number,
xpath?: string,
replacements?: Replacements,
slotHandler
parent?: NodeType,
node: NodeType,
index?: number,
}
const { props: { parent = null, node, index = 0, debug = 0, replacers, slotHandler, adjuster } } = Astro
const { name: Name, attributes } = node
if (debug) {
console.log('node.astro:debug', {node})
}
const nextDebug = debug ? debug - 1 : 0
---
{
node.type === TEXT_NODE ? <Fragment set:html={node.value}/>
: node.type === ELEMENT_NODE ? (
node.isSelfClosingTag ? <Name {...attributes}/>
: <Name {...attributes}>
<Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/>
</Name>
) : (
<Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/>
)
}