Hello World
This is a simple HTML demo
[![Rust](https://github.com/skubalj/build_html/actions/workflows/rust.yml/badge.svg)](https://github.com/skubalj/build_html/actions/workflows/rust.yml) build_html: Rust HTML Generation ============================== This crate allows HTML strings to be generated from within Rust code using the Builder pattern. Calls to add elements are repeatedly chained together to build up an HTML document. The struct is then flushed to a string which can be used elsewhere in your program. The strings generated by this library are unformatted, but are not explicitly minimized. Whitespace passed into a string will generally be preserved. Note that escaping strings is also not automatic, although a function to do so is provided. This crate is written in purely safe Rust with no production dependencies. ```rust use build_html::{HtmlElement, HtmlTag, Html}; let element = HtmlElement::new(HtmlTag::Div) .with_child( HtmlElement::new(HtmlTag::ParagraphText) .with_child("Paragraph Text".into()) .into() ) .with_child( HtmlElement::new(HtmlTag::PreformattedText) .with_child("Preformatted Text".into()) .into() ) .to_html_string(); assert_eq!(element, "
Paragraph Text
Preformatted Text
PARAGRAPH
", "" )); ``` ## A More Complicated Example ```rust use build_html::*; let html: String = HtmlPage::new() .with_title("My Page") .with_header(1, "Main Content:") .with_html( HtmlElement::new(HtmlTag::Article) .with_attribute("id", "article1") .with_header_attr(2, "Hello, World", [("id", "article-head"), ("class", "header")]) .with_paragraph("This is a simple HTML demo") ) .to_html_string(); ``` produces a string equivalent to: ```htmlThis is a simple HTML demo