-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Description
This code attempts to replace the last text node in a span:
fn main() {
use lol_html::html_content::ContentType;
use lol_html::{rewrite_str, text, RewriteStrSettings};
let html = rewrite_str(
r#"<span>Hello<b>hi</b></span>"#,
RewriteStrSettings {
element_content_handlers: vec![text!("span", |t| {
if t.last_in_text_node() {
t.replace(" world", ContentType::Text);
}
Ok(())
})],
..RewriteStrSettings::default()
},
)
.unwrap();
assert_eq!(html, r#"<span>Hello world<b>hi world</b></span>"#);
}Since there's only one span in the input, I'd expected this code to replace text with " world" once, probably just before the </span> tag, but either of the two actual replacement points would also seem reasonable.
Replacing at two positions seems strange. Is this expected behavior? If yes, what determines if a node is last_in_text_node()? And is there a way to distinguish these two positions (maybe using a span > * rule)?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels