@@ -120,10 +120,35 @@ extensions = ["tex"]
120
120
121
121
An escaper block consists of the attributes ` path ` and ` extensions ` . ` path `
122
122
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
124
127
the use of that escaper. Extensions are matched in order, starting with the
125
128
first escaper configured and ending with the default escapers for HTML
126
129
(extensions ` html ` , ` htm ` , ` xml ` , ` j2 ` , ` jinja ` , ` jinja2 ` ) and plain text
127
130
(no escaping; ` md ` , ` yml ` , ` none ` , ` txt ` , and the empty string). Note that
128
131
this means you can also define other escapers that match different extensions
129
132
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