Skip to content

Commit 7b91bab

Browse files
authored
Merge pull request #248 from GuillaumeGomez/missing-title
Add missing "Escapers" title in the book
2 parents afc0de1 + 27950a4 commit 7b91bab

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

book/src/configuration.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ The following keys can currently be used to customize template syntax:
108108
Values must be at least two characters long.
109109
If a key is omitted, the value from the default syntax is used.
110110

111+
## Escapers
112+
111113
Here is an example of a custom escaper:
112114

113115
```toml
@@ -118,10 +120,35 @@ extensions = ["tex"]
118120

119121
An escaper block consists of the attributes `path` and `extensions`. `path`
120122
contains a Rust identifier that must be in scope for templates using this
121-
escaper. `extensions` defines a list of file extensions that will trigger
123+
escaper. This type must implement the [`Escaper`]
124+
trait.
125+
126+
`extensions` defines a list of file extensions that will trigger
122127
the use of that escaper. Extensions are matched in order, starting with the
123128
first escaper configured and ending with the default escapers for HTML
124129
(extensions `html`, `htm`, `xml`, `j2`, `jinja`, `jinja2`) and plain text
125130
(no escaping; `md`, `yml`, `none`, `txt`, and the empty string). Note that
126131
this means you can also define other escapers that match different extensions
127132
to the same escaper.
133+
134+
You can then use templates with this extension or use the
135+
[`escape`](https://docs.rs/rinja/latest/rinja/filters/fn.escape.html) filter with
136+
the name of your extension in your template:
137+
138+
```jinja
139+
{{ some_string|escape("tex") }}
140+
```
141+
142+
As an example, we want `.js` files to be treated like "txt" files. To do so:
143+
144+
```toml
145+
[[escaper]]
146+
path = "rinja::filters::Text"
147+
extensions = ["js"]
148+
```
149+
150+
[`Text`](https://docs.rs/rinja/latest/rinja/filters/struct.Text.html) implements the
151+
[`Escaper`] trait so since we don't need want any escaping on our `.js` files, we use
152+
it.
153+
154+
[`Escaper`]: https://docs.rs/rinja/latest/rinja/filters/trait.Escaper.html

0 commit comments

Comments
 (0)