Skip to content

Commit 27950a4

Browse files
Add an escaper example
1 parent 7b44ef7 commit 27950a4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

book/src/configuration.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,35 @@ extensions = ["tex"]
120120

121121
An escaper block consists of the attributes `path` and `extensions`. `path`
122122
contains a Rust identifier that must be in scope for templates using this
123-
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
124127
the use of that escaper. Extensions are matched in order, starting with the
125128
first escaper configured and ending with the default escapers for HTML
126129
(extensions `html`, `htm`, `xml`, `j2`, `jinja`, `jinja2`) and plain text
127130
(no escaping; `md`, `yml`, `none`, `txt`, and the empty string). Note that
128131
this means you can also define other escapers that match different extensions
129132
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)