Crate write_html

source ·
Expand description

This crate provides a way to write HTML with as little overhead as possible.

This crate is still in development, and the API is not stable.

Example

use write_html::*;
use std::fmt::Write;

fn my_f() -> std::fmt::Result {
    let mut page = String::new();
    //page.reserve(1000);

    page.doctype();
    page.html_root("en")?
        .with(tags::head(Empty, Empty)
            .child(DefaultMeta)
            .child(tags::title(Empty, "Website!".as_html()))
        )?
        .with(tags::body(Empty, Empty)
            .child(tags::h1([("id", "h1")], "H1".as_html()))
            .child(tags::h2(Empty, "H2".as_html()))
            .child(tags::h3(Empty, "H3".as_html()))
            .child(tags::p(Empty, "Paragraph".as_html()))
            .child(tags::ol(
                Empty,
                [
                    tags::li(Empty, "Item 1".as_html()),
                    tags::li(Empty, "Item 2".as_html()),
                ],
            ))
            .child(tags::ol(Empty, Empty)
                .attr("style", "color: red")
                .child(tags::li(Empty, "Item 1".as_html()))
                .child(tags::li(Empty, "Item 2".as_html()))
                .child(tags::li(Empty, "Item 3".as_html()))
            )
    )?;

    Ok(())
}

my_f().unwrap();

Modules

  • Provides StringEscaper and HtmlEscaper to escape strings for use in string literals and HTML elements respectively.
  • Provides functions for creating common tags.

Macros

Structs

Enums

Traits

  • Something that can be converted into HTML.
  • Represents a name of an attribute.
  • Represents a value of an attribute.
  • Represents a list of attributes.
  • Represents a content that can be written to a Write as HTML.
  • Represents an environment that can write HTML.

Functions