Add markdown support

This commit is contained in:
2024-11-10 01:57:18 +01:00
parent eea2472f6b
commit cc99eecedd
6 changed files with 32 additions and 0 deletions

7
src/filters/markdown.rs Normal file
View File

@@ -0,0 +1,7 @@
use std::collections::HashMap;
pub fn markdown_filter(value: &tera::Value, _: &HashMap<String, tera::Value>) -> tera::Result<tera::Value> {
let value = tera::from_value::<String>(value.clone())?;
let md = markdown::to_html(&value);
Ok(tera::to_value(md)?)
}

1
src/filters/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod markdown;

View File

@@ -7,6 +7,8 @@ use loco_rs::{
};
use tracing::info;
use crate::filters;
const I18N_DIR: &str = "assets/i18n";
const I18N_SHARED: &str = "assets/i18n/shared.ftl";
@@ -28,6 +30,9 @@ impl Initializer for ViewEngineInitializer {
tera_engine
.tera
.register_function("t", FluentLoader::new(arc));
tera_engine
.tera
.register_filter("markdown", filters::markdown::markdown_filter);
info!("locales loaded");
}

View File

@@ -7,3 +7,4 @@ pub mod services;
pub mod tasks;
pub mod views;
pub mod workers;
pub mod filters;