Skip to content

Commit

Permalink
Merge pull request #38 from fabianbieler/main
Browse files Browse the repository at this point in the history
Serialize template contents
  • Loading branch information
rillian committed Oct 30, 2023
2 parents d3a5865 + c7506ae commit b0a6200
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
}

Expand Down
18 changes: 18 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ fn parse_and_serialize() {
);
}

#[test]
fn parse_and_serialize_with_template() {
let html = r"
<!doctype html>
<title>Test case</title>
<template><p>Content</p></template>";
let document = parse_html().one(html);
assert_eq!(
document.as_document().unwrap().quirks_mode(),
QuirksMode::NoQuirks
);
assert_eq!(
document.to_string(),
r"<!DOCTYPE html><html><head><title>Test case</title>
<template><p>Content</p></template></head><body></body></html>"
);
}

#[test]
fn parse_and_serialize_fragment() {
let html = r"<tbody><tr><td>Test case";
Expand Down

0 comments on commit b0a6200

Please sign in to comment.