77ef5056 by Adam Heath

Support Doctype, Document, and Comment node types.

1 parent cf25f14b
---
import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import { COMMENT_NODE, DOCTYPE_NODE, DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import type { NodeType } from 'ultrahtml'
import Children from './children.astro'
......@@ -25,13 +25,14 @@ if (debug) {
const nextDebug = debug ? debug - 1 : 0
---
{
node.type === TEXT_NODE ? <Fragment set:html={node.value}/>
node.type === DOCTYPE_NODE ? ''
: node.type === DOCUMENT_NODE ? <Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/>
: node.type === COMMENT_NODE ? <Fragment set:html={'<!-- ' + node.value + ' -->'}/>
: 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}/>
)
) : ''
}
......
import React from 'react'
import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import { COMMENT_NODE, DOCUMENT_NODE, DOCTYPE_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import { parseHtml, createMatcher, findNode } from 'astro-wt/html'
import { decode } from 'html-entities'
......@@ -73,7 +73,13 @@ export const Node = (props) => {
const { debug = 0, parent, node, index, replacers } = props
const { name: Name, attributes } = node
const nextDebug = debug ? debug - 1 : 0
if (node.type === TEXT_NODE) {
if (node.type === DOCTYPE_NODE) {
return ''
} else if (node.type === DOCUMENT_NODE) {
return Children({ debug: nextDebug, parent: node, children: node.children, replacers })
} else if (node.type === COMMENT_NODE) {
return '<!-- ' + node.value + ' -->'
} else if (node.type === TEXT_NODE) {
if (debug) console.log('Node:text', { value: node.value })
return node.value ? decode(node.value) : null
//return <React.Fragment dangerouslySetInnerHTML={{ __html: node.value }}/>
......