Trait write_html::HtmlEnv
source · pub trait HtmlEnv: Write + Sized {
// Provided methods
fn with(&mut self, html: impl Html) -> Result<&mut Self, Error> { ... }
fn doctype(&mut self) { ... }
fn text<'s>(&'s mut self) -> HtmlEscaper<'s, Self> { ... }
fn tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability
) -> Result<TagOpening<'s, 't, Self>, Error> { ... }
fn html_root<'s>(
&'s mut self,
lang: &str
) -> Result<InsideTagHtml<'s, 'static, Self>, Error> { ... }
fn html5_default_meta(&mut self) -> Result<&mut 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 text<'s>(&'s mut self) -> HtmlEscaper<'s, Self>
fn 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.text().write_str("Hello, <world>").unwrap();
assert_eq!(s, "Hello, <world>");
sourcefn tag<'s, 't>(
&'s mut self,
tag: &'t str,
compactability: Compactability
) -> Result<TagOpening<'s, 't, Self>, Error>
fn 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.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>");
sourcefn html_root<'s>(
&'s mut self,
lang: &str
) -> Result<InsideTagHtml<'s, 'static, Self>, Error>
fn html_root<'s>( &'s mut self, lang: &str ) -> Result<InsideTagHtml<'s, 'static, Self>, Error>
Adds a new root <html>
node to the HTML document.
See HtmlEnv::tag
for more information.
sourcefn html5_default_meta(&mut self) -> Result<&mut Self, Error>
fn html5_default_meta(&mut self) -> Result<&mut Self, Error>
Adds default <meta>
tags to the HTML document.
Example
use write_html::HtmlEnv;
let mut s = String::new();
s.html5_default_meta().unwrap();
assert_eq!(s, "<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\"><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");