markdown with GFM extension
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

This commit is contained in:
Alphonse Paix
2025-09-20 16:45:16 +02:00
parent c11e552d0a
commit c618de9732
2 changed files with 7 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
use chrono::{DateTime, Utc};
use markdown::message::Message;
use uuid::Uuid;
pub struct PostEntry {
@@ -15,10 +16,10 @@ impl PostEntry {
self.published_at.format("%B %d, %Y").to_string()
}
pub fn to_html(self) -> Self {
Self {
content: markdown::to_html(&self.content),
..self
pub fn to_html(self) -> Result<Self, anyhow::Error> {
match markdown::to_html_with_options(&self.content, &markdown::Options::gfm()) {
Ok(content) => Ok(Self { content, ..self }),
Err(e) => anyhow::bail!(e),
}
}
}

View File

@@ -52,7 +52,8 @@ pub async fn see_post(
.await
.context(format!("Failed to fetch post #{}", post_id))
.map_err(AppError::unexpected_page)?
.to_html();
.to_html()
.context("Could not render markdown with extension.")?;
let template = PostTemplate { post };
Ok(Html(template.render().unwrap()).into_response())
}