Collect NodeRefs so that they all get visited
parent
dc914b9977
commit
0c75749ae5
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rewrite-html-blocks"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -7,6 +7,7 @@ pub fn rewrite_tags(html: &str, selector: &str, mapping: impl Fn(&NodeRef) -> St
|
|||
for elem in document
|
||||
.select(selector)
|
||||
.expect("Failed to select document with given selector")
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
let node = elem.as_node();
|
||||
let new_contents = kuchiki::parse_fragment(
|
||||
|
@ -48,8 +49,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn remap_block() {
|
||||
let html = r#"<p>hello, world! <span id="replace-me">REPLACE ME</span></p>"#;
|
||||
let rewritten_html = rewrite_tags(html, "#replace-me", |_| {
|
||||
let html = r#"<p>hello, world! <span class="replace-me">REPLACE ME</span> <span class="replace-me me-too">me too!</span></p>"#;
|
||||
let rewritten_html = rewrite_tags(html, ".replace-me", |_| {
|
||||
"<strong>it's a me!</strong>".to_string()
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue