Trait write_html::HtmlEnv
source · pub trait HtmlEnv: Write + Sized {
// Provided methods
fn write_html(&mut self, html: impl Html) -> Result<&mut Self, Error> { ... }
fn doctype(&mut self) { ... }
fn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self> { ... }
fn open_tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability
) -> Result<TagOpening<'s, 't, Self>, Error> { ... }
}Expand description
Provided Methods§
sourcefn doctype(&mut self)
fn doctype(&mut self)
Writes the HTML5 doctype.
Example
use write_html::HtmlEnv;
let mut s = String::new();
s.doctype();
assert_eq!(s, "<!DOCTYPE html>");sourcefn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self>
fn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self>
Lets you write text into the HTML document, escaping it as necessary.
Example
use write_html::HtmlEnv;
use std::fmt::Write;
let mut s = String::new();
s.write_html_text().write_str("Hello, <world>").unwrap();
assert_eq!(s, "Hello, <world>");sourcefn open_tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability
) -> Result<TagOpening<'s, 't, Self>, Error>
fn open_tag<'s, 't>( &'s mut self, tag: &'t str, compactability: Compactability ) -> Result<TagOpening<'s, 't, Self>, Error>
Returns a tag opening, which lets you write attributes and inner HTML.
Arguments
tag- The tag name.compactability- Whether the tag can be compacted.
Example
use write_html::{HtmlEnv, Compactability};
use std::fmt::Write;
let mut s = String::new();
s.open_tag("h1", Compactability::No).unwrap()
.with_attr("id", "my-id").unwrap()
.inner_html().unwrap()
.write_str("Hello, world!").unwrap();
assert_eq!(s, "<h1 id=\"my-id\">Hello, world!</h1>");