5 ms·
Declarative syntax to express {HT|X|...}ML/DOM-like structures in your source code are a big win if that's a significant percentage of the boilerplate code you
by rcoder 4y ago
Declarative syntax to express {HT|X|...}ML/DOM-like structures in your source code are a big win if that's a significant percentage of the boilerplate code you have to write.
E.g.:
Literal HTML
```
<div class="active">Hello!</div>
```
Procedural JS
```
let elt = document.createElement('div');
elt.setAttribute("class", "active");
elt.innerText = "Hello!";
```
Rust literals + HTML macro
```
html! {
div(class: "active") {
"Hello!"
}
}
```
Modern Lisp (Clojure, Fennel, et. al.)
```
[:div {:class "active"} "Hello!"]
```
Dunno about you, but when I'm comparing my template source code to the materialized DOM in my browser dev tools, the latter is a _lot_ simpler for me to reason about.
- genezeta 4y agoJust so you know in case you don't, if you remove the ```backticks``` and just indent the line by 4 spaces it will be presented in a monospace font, like... <div class="active">Hello!</div> Ah, you can also get italics using asterisks instead of _underscores_.
- amelius 4y agoHow do you get a literal asterisk?
- steveklabnik 4y agoEither \* or **
- steveklabnik 4y agoYou only need two spaces, not four.
- genezeta 4y agoAh, yes. You're right, it's 2 :)