xhtml: Fix namespace on Body serialisation.

This commit is contained in:
Emmanuel Gil Peyrot 2019-09-05 11:51:05 +02:00
parent f528a45568
commit 24e862e352

View file

@ -52,9 +52,8 @@ impl XhtmlIm {
acc acc
}); });
let body = Body { let body = Body {
style: body.style,
xml_lang: body.xml_lang,
children, children,
..body
}; };
bodies.insert(lang, body); bodies.insert(lang, body);
} }
@ -100,12 +99,12 @@ impl From<XhtmlIm> for Element {
Element::builder("html") Element::builder("html")
.ns(ns::XHTML_IM) .ns(ns::XHTML_IM)
.append(wrapper.bodies.into_iter().map(|(ref lang, ref body)| { .append(wrapper.bodies.into_iter().map(|(ref lang, ref body)| {
assert_eq!(Some(lang), body.xml_lang.as_ref()); if lang.is_empty() {
Element::builder("body") assert!(body.xml_lang.is_none());
.ns(ns::XHTML_IM) } else {
.attr("style", get_style_string(body.style.clone())) assert_eq!(Some(lang), body.xml_lang.as_ref());
.attr("xml:lang", body.xml_lang.clone()) }
.append(children_to_nodes(body.children.clone())) Element::from(body.clone())
}).collect::<Vec<_>>()) }).collect::<Vec<_>>())
.build() .build()
} }
@ -473,9 +472,13 @@ mod tests {
let elem: Element = "<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><coucou>Hello world!</coucou></body></html>" let elem: Element = "<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><coucou>Hello world!</coucou></body></html>"
.parse() .parse()
.unwrap(); .unwrap();
let xhtml_im = XhtmlIm::try_from(elem).unwrap(); let parsed = XhtmlIm::try_from(elem).unwrap();
let html = xhtml_im.to_html(); let parsed2 = parsed.clone();
let html = parsed.to_html();
assert_eq!(html, "Hello world!"); assert_eq!(html, "Hello world!");
let elem = Element::from(parsed2);
assert_eq!(String::from(&elem), "<?xml version=\"1.0\" encoding=\"utf-8\"?><html xmlns=\"http://jabber.org/protocol/xhtml-im\"><body xmlns=\"http://www.w3.org/1999/xhtml\">Hello world!</body></html>");
} }
#[test] #[test]