Skip to content

Commit

Permalink
Book: document markdown filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski authored and djc committed Feb 21, 2022
1 parent 3efd753 commit 09429bb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions book/src/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ but are disabled by default. Enable them with Cargo features (see below for more

* **[Optional / feature gated filters][#optional-filters]:**
[`json|tojson`][#json],
[`markdown`][#markdown],
[`yaml`][#yaml]

* **[Custom filters][#custom-filters]**
Expand Down Expand Up @@ -369,6 +370,30 @@ Ugly: <script>var data = "{{data|json}}";</script>
Ugly: <script>var data = '{{data|json|safe}}';</script>
```

### `markdown`
[#markdown]: #markdown

Enabling the `markdown` feature will enable the use of the `markdown` filter.
This will render a value using a [GitHub flavored CommonMark](https://docs.rs/comrak/0.12.*/comrak/) syntax.
By default the extensions “autolink”, “strikethrough”, “tagfilter”, and “table” are enabled.
Any raw HTML gets escaped.

```jinja
{{ "**<i>Hello</i>, world!**"|markdown }}
```

Output:

```html
<p><strong>&lt;i&gt;Hello&lt;/i&gt;, world!</strong></p>
```

You can change the default settings by supplying [custom options][ComrakRenderOptions], e.g. to enable unsafe raw HTML.
You can find a usage example in our [unit tests][markdown-tests].

[ComrakRenderOptions]: https://docs.rs/comrak/0.12.*/comrak/struct.ComrakRenderOptions.html
[markdown-tests]: https://github.com/djc/askama/blob/5748c357d435b24848d1571df010d777859fede9/testing/tests/markdown.rs#L36-L75

### `yaml`
[#yaml]: #yaml

Expand Down

0 comments on commit 09429bb

Please sign in to comment.