Home

Setup HTML Escaping For Files With A Different Extension In Minijinja

Note

This is a draft with just the code snippet.

More details coming when I can get to them.

rust
use minijinja::AutoEscape;

fn create_env(path: &str) -> Environment<'static> {
    let mut env = Environment::new();
    env.set_source(Source::from_path(path));
    env.set_auto_escape_callback(|name| {
    if matches!(name.rsplit('.').next().unwrap_or(""), "html" | "jinja") {
        AutoEscape::Html
    } else {
        AutoEscape::None
    }
});
    env
}
~ fin ~