Add markdown rendering for recipe descriptions using comrak

This commit is contained in:
Greg Burri 2025-04-02 18:19:06 +02:00
parent 9b89117a66
commit 0c2e4b7624
3 changed files with 12 additions and 1 deletions

View file

@ -28,6 +28,7 @@ clap = { version = "4", features = ["derive"] }
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] } sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] }
askama = "0.13" askama = "0.13"
comrak = "0.37"
argon2 = { version = "0.5", features = ["default", "std"] } argon2 = { version = "0.5", features = ["default", "std"] }
rand_core = { version = "0.9", features = ["std"] } rand_core = { version = "0.9", features = ["std"] }

View file

@ -18,6 +18,16 @@ impl Recipes {
} }
} }
mod filters {
use askama::filters::Safe;
pub fn markdown<T: std::fmt::Display>(s: T) -> askama::Result<Safe<String>> {
Ok(Safe(comrak::markdown_to_html(
&s.to_string(),
&comrak::ComrakOptions::default(),
)))
}
}
#[derive(Template)] #[derive(Template)]
#[template(path = "home.html")] #[template(path = "home.html")]
pub struct HomeTemplate { pub struct HomeTemplate {

View file

@ -51,7 +51,7 @@
{% if !recipe.description.is_empty() %} {% if !recipe.description.is_empty() %}
<div class="recipe-description" > <div class="recipe-description" >
{{ recipe.description }} {{ recipe.description | markdown }}
</div> </div>
{% endif %} {% endif %}