external.astro
779 Bytes
---
import { parseHtml, createMatcher, findNode } from './html.ts'
import Match from './match.astro'
const { props } = Astro
const { debug, replacers, slotHandler } = props
const adjustmentsCompiled = Object.entries(adjustments).map(([ selector, handler ]) => [ createMatcher(selector), handler ])
const adjuster = (node, parent, index) => {
for (const [ matcher, handler ] of adjustmentsCompiled) {
if (matcher(node, parent, index, false)) {
node = handler(node)
}
}
return node
}
const doc = props.node ? props.node : parseHtml(props.html, { adjuster })
const node = xpath ? findNode(doc, xpath) : doc
const nextDebug = debug ? debug - 1 : 0
---
<Match node={node} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/>