@@ -108,6 +108,8 @@ The following keys can currently be used to customize template syntax:
108
108
Values must be at least two characters long.
109
109
If a key is omitted, the value from the default syntax is used.
110
110
111
+ ## Escapers
112
+
111
113
Here is an example of a custom escaper:
112
114
113
115
``` toml
@@ -118,10 +120,35 @@ extensions = ["tex"]
118
120
119
121
An escaper block consists of the attributes ` path ` and ` extensions ` . ` path `
120
122
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
122
127
the use of that escaper. Extensions are matched in order, starting with the
123
128
first escaper configured and ending with the default escapers for HTML
124
129
(extensions ` html ` , ` htm ` , ` xml ` , ` j2 ` , ` jinja ` , ` jinja2 ` ) and plain text
125
130
(no escaping; ` md ` , ` yml ` , ` none ` , ` txt ` , and the empty string). Note that
126
131
this means you can also define other escapers that match different extensions
127
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