Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vidhanio/html-node
HTML nodes in Rust.
https://github.com/vidhanio/html-node
html macro macros procedural-macros rust rust-lang
Last synced: 13 days ago
JSON representation
HTML nodes in Rust.
- Host: GitHub
- URL: https://github.com/vidhanio/html-node
- Owner: vidhanio
- License: mit
- Created: 2023-07-27T02:34:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-02T20:23:03.000Z (3 months ago)
- Last Synced: 2024-10-14T02:16:54.316Z (about 1 month ago)
- Topics: html, macro, macros, procedural-macros, rust, rust-lang
- Language: Rust
- Homepage: https://docs.rs/html-node
- Size: 137 KB
- Stars: 50
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# `html-node`
HTML nodes in Rust. \[powered by [rstml](https://github.com/rs-tml/rstml)\].
## Note
If you want to use this purely for building websites in rust, consider using my other library, [hypertext](https://github.com/vidhanio/hypertext). It puts performance and type-checking first, and supports this crate's syntax as well as [maud](https://maud.lambda.xyz)'s syntax, which is much cleaner.
## Features
- Text escaping
- Pretty-printing
- Customizable compile-time type-checked elements and attributes ([docs](https://docs.rs/html-node/latest/html_node/typed/index.html))
- completely optional, and can be mixed with untyped elements when needed!## Example
```rust
let shopping_list = vec!["milk", "eggs", "bread"];let shopping_list_html = html! {
Shopping List
{ shopping_list.into_iter().zip(1..).map(|(item, i)| html! {
{text!("{item}")}
}) }
};
```HTML Output
```rust
// the `#` flag enables pretty-printing
println!("{shopping_list_html:#}");
``````html
Shopping List
milk
eggs
bread
```Rust Output
```rust
println!("{shopping_list_html:#?}");
``````rust
Element(
Element {
name: "div",
attributes: [],
children: Some(
[
Element(
Element {
name: "h1",
attributes: [],
children: Some(
[
Text(
Text {
text: "Shopping List",
},
),
],
),
},
),
Element(
Element {
name: "ul",
attributes: [],
children: Some(
[
Fragment(
Fragment {
children: [
Element(
Element {
name: "li",
attributes: [
(
"class",
Some(
"item",
),
),
],
children: Some(
[
Element(
Element {
name: "input",
attributes: [
(
"type",
Some(
"checkbox",
),
),
(
"id",
Some(
"item-1",
),
),
],
children: None,
},
),
Element(
Element {
name: "label",
attributes: [
(
"for",
Some(
"item-1",
),
),
],
children: Some(
[
Text(
Text {
text: "milk",
},
),
],
),
},
),
],
),
},
),
Element(
Element {
name: "li",
attributes: [
(
"class",
Some(
"item",
),
),
],
children: Some(
[
Element(
Element {
name: "input",
attributes: [
(
"type",
Some(
"checkbox",
),
),
(
"id",
Some(
"item-2",
),
),
],
children: None,
},
),
Element(
Element {
name: "label",
attributes: [
(
"for",
Some(
"item-2",
),
),
],
children: Some(
[
Text(
Text {
text: "eggs",
},
),
],
),
},
),
],
),
},
),
Element(
Element {
name: "li",
attributes: [
(
"class",
Some(
"item",
),
),
],
children: Some(
[
Element(
Element {
name: "input",
attributes: [
(
"type",
Some(
"checkbox",
),
),
(
"id",
Some(
"item-3",
),
),
],
children: None,
},
),
Element(
Element {
name: "label",
attributes: [
(
"for",
Some(
"item-3",
),
),
],
children: Some(
[
Text(
Text {
text: "bread",
},
),
],
),
},
),
],
),
},
),
],
},
),
],
),
},
),
],
),
},
)
```