Hello! Given the following code, the end result of document doesn't have the changes to head BUT when I log the children of head after the loop, I can see the changes are in head, but the head in document never gets modified. Does anyone know what I'm doing wrong?
fn add_style_tags(&self, html: String, parts: HashMap<String, MessagePart>) -> Result<String, Box<dyn Error>> {
let document = kuchiki::parse_html().one(html.to_string());
let head = match document.select_first("head") {
Ok(h) => h,
Err(_) => return Err(ParserError::new("No selector matches head").into()),
}.as_node().clone();
for (_key, value) in parts {
let content_type = match value.content_type {
Some(c) => c,
None => continue,
};
println!("Content type: {}", content_type);
if content_type != TEXT_CSS.to_string() {
continue;
}
let style_content = kuchiki::NodeRef::new_text(value.content.unwrap());
let style = kuchiki::NodeRef::new_element(QualName::new(None, ns!(html), local_name!("style")), vec![]);
style.append(style_content);
head.append(style);
}
Ok(document.to_string())
}
Hello! Given the following code, the end result of document doesn't have the changes to head BUT when I log the children of head after the loop, I can see the changes are in head, but the head in document never gets modified. Does anyone know what I'm doing wrong?