Add markdown rendering for recipe descriptions using comrak
This commit is contained in:
parent
9b89117a66
commit
0c2e4b7624
3 changed files with 12 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ clap = { version = "4", features = ["derive"] }
|
|||
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio", "chrono"] }
|
||||
|
||||
askama = "0.13"
|
||||
comrak = "0.37"
|
||||
|
||||
argon2 = { version = "0.5", features = ["default", "std"] }
|
||||
rand_core = { version = "0.9", features = ["std"] }
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
#[template(path = "home.html")]
|
||||
pub struct HomeTemplate {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
|
||||
{% if !recipe.description.is_empty() %}
|
||||
<div class="recipe-description" >
|
||||
{{ recipe.description }}
|
||||
{{ recipe.description | markdown }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue