Add Document struct

This commit is contained in:
Joscha 2024-11-27 00:14:27 +01:00
parent bc7a659303
commit d18f9d2171
2 changed files with 15 additions and 0 deletions

View file

@ -99,3 +99,9 @@ impl Element {
self self
} }
} }
/// An HTML document.
///
/// A `Document(el)` is basically the same as `[Content::doctype(), el.into()]`
/// for the purposes of the [`crate::Render`] trait.
pub struct Document(pub Element);

View file

@ -3,6 +3,7 @@ use std::{error, fmt};
use crate::{ use crate::{
check, check,
element::{Content, Element, ElementKind}, element::{Content, Element, ElementKind},
Document,
}; };
#[derive(Debug)] #[derive(Debug)]
@ -81,6 +82,14 @@ pub trait Render {
} }
} }
impl Render for Document {
fn render<W: fmt::Write>(&self, w: &mut W) -> Result<()> {
Content::doctype().render(w)?;
self.0.render(w)?;
Ok(())
}
}
impl Render for [Content] { impl Render for [Content] {
fn render<W: fmt::Write>(&self, w: &mut W) -> Result<()> { fn render<W: fmt::Write>(&self, w: &mut W) -> Result<()> {
for content in self { for content in self {