Add Element::into_document

It's more convenient in some cases and also makes the example code less
"misleading": Now the string represents a full, correct HTML document.
This commit is contained in:
Joscha 2024-12-02 21:48:46 +01:00
parent b377ee2936
commit 6f0ae129fa
4 changed files with 20 additions and 10 deletions

View file

@ -49,6 +49,7 @@
//! p(("This is an example for a ", em("simple"), " web page.")),
//! )),
//! ))
//! .into_document()
//! .render_to_string()
//! .unwrap();
//! ```
@ -80,21 +81,20 @@ pub use self::{element::*, render::*};
#[cfg(test)]
mod tests {
use crate::{html::*, Attr, Content, Element, Render};
use crate::{html::*, Attr, Element, Render};
#[test]
fn simple_website() {
let els = [
Content::doctype(),
html((
head(title("Hello")),
body((h1("Hello"), p(("Hello ", em("world"), "!")))),
))
.into(),
];
let page = html((
head(title("Hello")),
body((h1("Hello"), p(("Hello ", em("world"), "!")))),
))
.into_document()
.render_to_string()
.unwrap();
assert_eq!(
els.render_to_string().unwrap(),
page,
concat!(
"<!DOCTYPE html><html>",
"<head><title>Hello</title></head>",