Support Doctype, Document, and Comment node types.
Showing
2 changed files
with
14 additions
and
7 deletions
| 1 | --- | 1 | --- |
| 2 | import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml' | 2 | import { COMMENT_NODE, DOCTYPE_NODE, DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml' |
| 3 | import type { NodeType } from 'ultrahtml' | 3 | import type { NodeType } from 'ultrahtml' |
| 4 | import Children from './children.astro' | 4 | import Children from './children.astro' |
| 5 | 5 | ||
| ... | @@ -25,13 +25,14 @@ if (debug) { | ... | @@ -25,13 +25,14 @@ if (debug) { |
| 25 | const nextDebug = debug ? debug - 1 : 0 | 25 | const nextDebug = debug ? debug - 1 : 0 |
| 26 | --- | 26 | --- |
| 27 | { | 27 | { |
| 28 | node.type === TEXT_NODE ? <Fragment set:html={node.value}/> | 28 | node.type === DOCTYPE_NODE ? '' |
| 29 | : node.type === DOCUMENT_NODE ? <Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler}/> | ||
| 30 | : node.type === COMMENT_NODE ? <Fragment set:html={'<!-- ' + node.value + ' -->'}/> | ||
| 31 | : node.type === TEXT_NODE ? <Fragment set:html={node.value}/> | ||
| 29 | : node.type === ELEMENT_NODE ? ( | 32 | : node.type === ELEMENT_NODE ? ( |
| 30 | node.isSelfClosingTag ? <Name {...attributes}/> | 33 | node.isSelfClosingTag ? <Name {...attributes}/> |
| 31 | : <Name {...attributes}> | 34 | : <Name {...attributes}> |
| 32 | <Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/> | 35 | <Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/> |
| 33 | </Name> | 36 | </Name> |
| 34 | ) : ( | 37 | ) : '' |
| 35 | <Children parent={node} children={node.children} debug={nextDebug} replacers={replacers} slotHandler={slotHandler} adjuster={adjuster}/> | ||
| 36 | ) | ||
| 37 | } | 38 | } | ... | ... |
| 1 | import React from 'react' | 1 | import React from 'react' |
| 2 | 2 | ||
| 3 | import { ELEMENT_NODE, TEXT_NODE } from 'ultrahtml' | 3 | import { COMMENT_NODE, DOCUMENT_NODE, DOCTYPE_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml' |
| 4 | import { parseHtml, createMatcher, findNode } from 'astro-wt/html' | 4 | import { parseHtml, createMatcher, findNode } from 'astro-wt/html' |
| 5 | import { decode } from 'html-entities' | 5 | import { decode } from 'html-entities' |
| 6 | 6 | ||
| ... | @@ -73,7 +73,13 @@ export const Node = (props) => { | ... | @@ -73,7 +73,13 @@ export const Node = (props) => { |
| 73 | const { debug = 0, parent, node, index, replacers } = props | 73 | const { debug = 0, parent, node, index, replacers } = props |
| 74 | const { name: Name, attributes } = node | 74 | const { name: Name, attributes } = node |
| 75 | const nextDebug = debug ? debug - 1 : 0 | 75 | const nextDebug = debug ? debug - 1 : 0 |
| 76 | if (node.type === TEXT_NODE) { | 76 | if (node.type === DOCTYPE_NODE) { |
| 77 | return '' | ||
| 78 | } else if (node.type === DOCUMENT_NODE) { | ||
| 79 | return Children({ debug: nextDebug, parent: node, children: node.children, replacers }) | ||
| 80 | } else if (node.type === COMMENT_NODE) { | ||
| 81 | return '<!-- ' + node.value + ' -->' | ||
| 82 | } else if (node.type === TEXT_NODE) { | ||
| 77 | if (debug) console.log('Node:text', { value: node.value }) | 83 | if (debug) console.log('Node:text', { value: node.value }) |
| 78 | return node.value ? decode(node.value) : null | 84 | return node.value ? decode(node.value) : null |
| 79 | //return <React.Fragment dangerouslySetInnerHTML={{ __html: node.value }}/> | 85 | //return <React.Fragment dangerouslySetInnerHTML={{ __html: node.value }}/> | ... | ... |
-
Please register or sign in to post a comment