Expand description
Server-side Markdown → HTML rendering for page bodies.
Authors write markdown in the admin (via the extension-field
editor). At render time, pulldown-cmark converts to HTML; the
result is then run through ammonia so any embedded <script>,
event handlers, javascript: hrefs, or other XSS vectors are
stripped before reaching the browser.
Exposed as the Tera filter markdown. Use it like:
{{ extension.body_markdown | markdown | safe }}The | safe is required — the filter returns trusted HTML, and
without safe Tera would re-escape the angle brackets.
Functions§
- register_
tera_ filter - Register the
markdownfilter on a Tera instance. Host apps already callingcrate::translation::register_tera_filtershould call this too so{{ … | markdown }}resolves. - render
- Convert a markdown source string to sanitized HTML.
- sanitize_
html - Sanitize an HTML string for richtext storage / preview. Uses the same
ammonia allow-list as the markdown renderer, PLUS the move-safe
internal-link attributes
<a linktype="page|media" id="N">that the| richtextfilter resolves to real URLs at render time. Ammonia’s default policy strips unknown<a>attributes, which would drop thelinktype/idpair and turn move-safe links into broken ones the next time a page is moved — so they’re explicitly allow-listed here. Both are inert (no script/URL vector), so allowing them is XSS-safe. Used by the richtext on-save sanitizer (sanitized_extension_form) and the preview pane.