From 24e862e35290e88e3b25591fe431c36610e1af47 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 5 Sep 2019 11:51:05 +0200 Subject: [PATCH] xhtml: Fix namespace on Body serialisation. --- src/xhtml.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/xhtml.rs b/src/xhtml.rs index 8b9635e6..224e0bb5 100644 --- a/src/xhtml.rs +++ b/src/xhtml.rs @@ -52,9 +52,8 @@ impl XhtmlIm { acc }); let body = Body { - style: body.style, - xml_lang: body.xml_lang, children, + ..body }; bodies.insert(lang, body); } @@ -100,12 +99,12 @@ impl From for Element { Element::builder("html") .ns(ns::XHTML_IM) .append(wrapper.bodies.into_iter().map(|(ref lang, ref body)| { - assert_eq!(Some(lang), body.xml_lang.as_ref()); - Element::builder("body") - .ns(ns::XHTML_IM) - .attr("style", get_style_string(body.style.clone())) - .attr("xml:lang", body.xml_lang.clone()) - .append(children_to_nodes(body.children.clone())) + if lang.is_empty() { + assert!(body.xml_lang.is_none()); + } else { + assert_eq!(Some(lang), body.xml_lang.as_ref()); + } + Element::from(body.clone()) }).collect::>()) .build() } @@ -473,9 +472,13 @@ mod tests { let elem: Element = "Hello world!" .parse() .unwrap(); - let xhtml_im = XhtmlIm::try_from(elem).unwrap(); - let html = xhtml_im.to_html(); + let parsed = XhtmlIm::try_from(elem).unwrap(); + let parsed2 = parsed.clone(); + let html = parsed.to_html(); assert_eq!(html, "Hello world!"); + + let elem = Element::from(parsed2); + assert_eq!(String::from(&elem), "Hello world!"); } #[test]