Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
77ef5056
authored
2024-11-27 10:04:51 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Support Doctype, Document, and Comment node types.
1 parent
cf25f14b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
7 deletions
lib/node.astro
lib/react.jsx
lib/node.astro
View file @
77ef505
---
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}/>
)
) : ''
}
...
...
lib/react.jsx
View file @
77ef505
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 }}/>
...
...
Please
register
or
sign in
to post a comment