Expand description

Straightforward HTML document building. Write your HTML with the full power of a programming language instead of creating messy and confusing templates that contain typing errors.

API example

use lewp_html::{api::*, LanguageTag, Script, DocumentExt, NodeExt};

let valid_html = document(LanguageTag::parse("de-DE").unwrap(),
   head(vec![
       script(Script::Src("/my-javascript")),
       script(Script::Inline("console.log(\"hello world!\");")),
       link("text/css", "/static/css/main.css")
   ]),
   body(
       vec![
       h1(vec![text("Hello World")]),
       p(vec![text("This is a paragraph!")])
           .attrs(vec![
               ("class", "prelude"),
               ("id", "first-paragraph")
           ]),
       h2(vec![text("The elegant way to create a DOM!")]),
       p(vec![text("Creating DOM has never been easier.")])
           .attr("class", "highlighted")
       ])
).into_html();

let expected_html = "<!DOCTYPE html><html lang=\"de\"><head><script src=\"/my-javascript\"></script><script>console.log(\"hello world!\");</script><link href=\"/static/css/main.css\" type=\"text/css\"></head><body><h1>Hello World</h1><p class=\"prelude\" id=\"first-paragraph\">This is a paragraph!</p><h2>The elegant way to create a DOM!</h2><p class=\"highlighted\">Creating DOM has never been easier.</p></body></html>";

assert_eq!(&valid_html, expected_html);

Modules

API function definitions to create your html document. See the API example above.

Macros

Error log with added prefix for this crate.

Enums

A browsing context is an environment in which Document objects are presented to the user.

A Mime charset.

Language tag with borrowed data.

Parameter for the script element.

Traits

Methods for easy handling of an HTML document.

Methods for easy interaction with a DOM Node.

Type Definitions

An HTML5 document.

A HTML5 node.

A list of nodes.