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
2d8750b4
authored
2024-11-27 08:36:21 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update react side for adjustments and multiple xpath matches.
1 parent
1367a306
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
lib/react.jsx
lib/react.jsx
View file @
2d8750b
import
React
from
'react'
import
{
COMMENT_NODE
,
DOCUMENT_NODE
,
DOCTYPE_NODE
,
ELEMENT_NODE
,
TEXT_NODE
}
from
'ultrahtml'
import
{
parseHtml
,
createMatcher
,
findNode
}
from
'astro-wt/html'
import
{
parseHtml
,
create
Adjuster
,
create
Matcher
,
findNode
}
from
'astro-wt/html'
import
{
decode
}
from
'html-entities'
export
const
ReparseStaticChildren
=
(
replaceOptions
,
Component
)
=>
(
props
)
=>
{
...
...
@@ -43,13 +43,14 @@ export const CreateReplacement = (Element, propsOrCreator) => (matchOptions) =>
export
const
DeleteHandler
=
()
=>
null
export
const
Replace
=
(
props
)
=>
{
const
{
debug
=
0
,
html
,
xpath
,
replacements
}
=
props
const
doc
=
props
.
node
?
props
.
node
:
parseHtml
(
html
,
{
react
:
false
})
const
node
=
xpath
?
findNode
(
doc
,
xpath
)
:
doc
const
{
debug
=
0
,
html
,
xpath
,
adjustments
,
replacements
}
=
props
const
adjuster
=
createAdjuster
(
adjustments
)
const
doc
=
props
.
node
?
props
.
node
:
parseHtml
(
html
,
{
adjuster
})
const
nodes
=
xpath
?
findNode
(
doc
,
xpath
,
{
single
:
false
})
:
[
doc
]
const
replacers
=
Object
.
entries
(
replacements
).
map
(([
selector
,
Handler
])
=>
[
createMatcher
(
selector
),
Handler
])
const
nextDebug
=
debug
?
debug
-
1
:
0
if
(
debug
)
console
.
log
(
'Replace'
,
{
html
,
replacers
,
node
})
const
result
=
Match
({
debug
:
nextDebug
,
node
,
replacers
}
)
const
result
=
nodes
.
map
(
node
=>
Match
({
debug
:
nextDebug
,
node
,
replacers
})
)
if
(
debug
)
console
.
log
(
'Replace result'
,
result
)
return
result
}
...
...
Please
register
or
sign in
to post a comment