markdown with GFM extension
This commit is contained in:
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user