Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.
13 changes: 11 additions & 2 deletions src/concepts/html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
description: The procedural macro for generating HTML and SVG
---

# Using html!
# Using `html!`
Comment thread
zoechi marked this conversation as resolved.
Outdated

The `html!` macro allows you to write HTML and SVG code declaratively. It is similar to JSX \(a Javascript extension which allows you to write HTML code inside of Javascript\).

**Important notes**

1. The `html!` macro only accepts one root html node \(you can counteract this by [using fragments or iterators](lists.md)\)
2. An empty `html! {}` invocation is valid and will not render anything
3. Literals must always be quoted and wrapped in braces: `html! { "Hello, World" }`
3. Literals in element content must always be quoted and wrapped in braces
Comment thread
zoechi marked this conversation as resolved.
Outdated
* `html! { "Hello, World" }`
* `html! { <div>{ "Hell, World" }</div> }`
* `html! { <div>{ String::from("foo") + "bar" }</div>`
4. Quoted attribute values are taken literally
Comment thread
zoechi marked this conversation as resolved.
Outdated
* `html! { <div> id="bar"</div> }`
5. Unquoted attribute values are interpreted as expressions
Comment thread
zoechi marked this conversation as resolved.
Outdated
* `let foo = "bar"; html! { <div id=foo></div> }`
* `html! { <div id=String::from("foo") + "bar"></div> }`
Comment on lines +18 to +22

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing because literals are also expressions. I'd prefer if we left these notes out


{% hint style="info" %}
The `html!` macro can reach easily the default recursion limit of the compiler. It is advised to bump its value if you encouter compilation errors. Use an attribute like `#![recursion_limit="1024"]` to bypass the problem. See the [official documentation](https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute) and [this Stack Overflow question](https://stackoverflow.com/questions/27454761/what-is-a-crate-attribute-and-where-do-i-add-it) for details.
{% endhint %}
Expand Down