From c7506aea61ebb68832918c106a6219dcd189fa52 Mon Sep 17 00:00:00 2001 From: Fabian Bieler Date: Fri, 27 Oct 2023 07:27:49 +0200 Subject: [PATCH] Serialize template contents --- src/serializer.rs | 7 ++++++- src/tests.rs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/serializer.rs b/src/serializer.rs index b0456762..7237718a 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -41,7 +41,12 @@ impl Serialize for NodeRef { )? } - for child in self.children() { + let children = match element.template_contents.as_ref() { + Some(template_root) => template_root.children(), + None => self.children(), + }; + + for child in children { Serialize::serialize(&child, serializer, IncludeNode)? } diff --git a/src/tests.rs b/src/tests.rs index a4f39e58..729d13ab 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -56,6 +56,24 @@ fn parse_and_serialize() { ); } +#[test] +fn parse_and_serialize_with_template() { + let html = r" + +Test case +"; + let document = parse_html().one(html); + assert_eq!( + document.as_document().unwrap().quirks_mode(), + QuirksMode::NoQuirks + ); + assert_eq!( + document.to_string(), + r"Test case +" + ); +} + #[test] fn parse_and_serialize_fragment() { let html = r"Test case";