2020-11-02 12:53:27 +13:00
|
|
|
# Text and escaping
|
|
|
|
|
|
|
|
## Text
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
Literal strings use the same syntax as Rust.
|
|
|
|
Wrap them in double quotes,
|
|
|
|
and use a backslash for escapes.
|
2020-11-02 12:53:27 +13:00
|
|
|
|
|
|
|
```rust
|
2021-01-15 17:40:46 +13:00
|
|
|
# let _ = maud::
|
2020-11-02 12:53:27 +13:00
|
|
|
html! {
|
|
|
|
"Oatmeal, are you crazy?"
|
|
|
|
}
|
2021-01-15 17:40:46 +13:00
|
|
|
# ;
|
2020-11-02 12:53:27 +13:00
|
|
|
```
|
|
|
|
|
|
|
|
## Raw strings
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
If the string is long,
|
|
|
|
or contains many special characters,
|
|
|
|
then it may be worth using [raw strings] instead:
|
2020-11-02 12:53:27 +13:00
|
|
|
|
|
|
|
```rust
|
2021-01-15 17:40:46 +13:00
|
|
|
# let _ = maud::
|
2020-11-02 12:53:27 +13:00
|
|
|
html! {
|
|
|
|
pre {
|
|
|
|
r#"
|
|
|
|
Rocks, these are my rocks.
|
|
|
|
Sediments make me sedimental.
|
|
|
|
Smooth and round,
|
|
|
|
Asleep in the ground.
|
|
|
|
Shades of brown
|
|
|
|
And gray.
|
|
|
|
"#
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 17:40:46 +13:00
|
|
|
# ;
|
2020-11-02 12:53:27 +13:00
|
|
|
```
|
|
|
|
|
|
|
|
[raw strings]: https://doc.rust-lang.org/reference/tokens.html#raw-string-literals
|
|
|
|
|
|
|
|
## Escaping and `PreEscaped`
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
By default,
|
|
|
|
HTML special characters are escaped automatically.
|
|
|
|
Wrap the string in `(PreEscaped())` to disable this escaping.
|
|
|
|
(See the section on [splices](splices-toggles.md) to
|
|
|
|
learn more about how this works.)
|
2020-11-02 12:53:27 +13:00
|
|
|
|
|
|
|
```rust
|
|
|
|
use maud::PreEscaped;
|
2021-01-15 17:40:46 +13:00
|
|
|
# let _ = maud::
|
2020-11-02 12:53:27 +13:00
|
|
|
html! {
|
|
|
|
"<script>alert(\"XSS\")</script>" // <script>...
|
|
|
|
(PreEscaped("<script>alert(\"XSS\")</script>")) // <script>...
|
|
|
|
}
|
2021-01-15 17:40:46 +13:00
|
|
|
# ;
|
2020-11-02 12:53:27 +13:00
|
|
|
```
|
|
|
|
|
|
|
|
## The `DOCTYPE` constant
|
|
|
|
|
2021-01-22 19:31:51 +13:00
|
|
|
If you want to add a `<!DOCTYPE html>` declaration to your page,
|
|
|
|
you may use the `maud::DOCTYPE` constant
|
|
|
|
instead of writing it out by hand:
|
2020-11-02 12:53:27 +13:00
|
|
|
|
|
|
|
```rust
|
|
|
|
use maud::DOCTYPE;
|
2021-01-15 17:40:46 +13:00
|
|
|
# let _ = maud::
|
2020-11-02 12:53:27 +13:00
|
|
|
html! {
|
|
|
|
(DOCTYPE) // <!DOCTYPE html>
|
|
|
|
}
|
2021-01-15 17:40:46 +13:00
|
|
|
# ;
|
2020-11-02 12:53:27 +13:00
|
|
|
```
|