Add Document struct
This commit is contained in:
parent
bc7a659303
commit
d18f9d2171
2 changed files with 15 additions and 0 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue