maud 0.1.2

Compile-time HTML templates. failed to build maud-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure builds.
If you believe this is' fault, open an issue.
Visit the last successful build: maud-0.23.0

A macro for writing HTML templates.

This crate, along with its sister maud_macros, lets you generate HTML markup from within Rust. It exposes a single macro, html!, which compiles your markup to specialized Rust code.


To get started, add maud and maud_macros to your Cargo.toml:

# ...
maud = "*"
maud_macros = "*"



extern crate maud;
#[plugin] #[no_link] extern crate maud_macros;

fn main() {
    let name = "Lyra";
    let markup = html! {
        p { "Hi, " $name "!" }
    assert_eq!(markup.render(), "<p>Hi, Lyra!</p>");


Note: The markup you see below has been cleaned up a bit. In reality, Maud doesn't add extra whitespace to the HTML it generates.


html! {
    "Oatmeal, are you crazy?\n"
Oatmeal, are you crazy?

Literal strings use the same syntax as Rust. Wrap them in double quotes, and use a backslash for escapes.

By default, HTML special characters are escaped automatically. Add a $$ prefix to disable this escaping. (This is a special case of the splice syntax described below.)


html! {
    h1 "Pinkie's Brew"
    p {
        "Watch as I work my gypsy magic"
        br /
        "Eye of a newt and cinnamon"
    p small em "squee"
<h1>Pinkie's Brew</h1>
  Watch as I work my gypsy magic
  Eye of a newt and cinnamon

Write an element using curly braces (p {}).

Terminate a void element using a slash (br /).

If the element has only a single child, you can omit the brackets (h1 "Pinkie's Brew"). This shorthand works with nested elements too.


html! {
    form method="POST" {
        label for="waffles" "Do you like waffles?"
        input name="waffles" type="checkbox" checked=! /
<form method="POST">
  <label for="waffles">Do you like waffles?</label>
  <input name="waffles" type="checkbox" checked>

Add attributes using the syntax attr="value". Attributes must be quoted: they are parsed as string literals.

To declare an empty attribute, use ! for the value: checked=!.


let best_pony = "Pinkie Pie";
let numbers = [1, 2, 3, 4];
let secret_message = "Surprise!";
let pre_escaped = "<p>Pre-escaped</p>";
html! {
    h1 { $best_pony " says:" }
    p {
        "I have " $numbers.len() " numbers, "
        "and the first one is " $numbers[0]
    p title=$secret_message {
        "1 + 1 = " $(1 + 1)
<h1>Pinkie Pie says:</h1>
<p>I have 4 numbers, and the first one is 1</p>
<p title="Surprise!">1 + 1 = 2</p>

Use $(expr) syntax to splice a Rust expression into the output. The expression may evaluate to anything that implements std::fmt::Display.

You can omit the brackets if it's just a variable ($var), indexing operation ($var[0]), method call ($var.method()), or property lookup ($

As with literals, expression values are escaped by default. Use a $$ prefix to disable this behavior.