markdown with GFM extension
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
use markdown::message::Message;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct PostEntry {
|
pub struct PostEntry {
|
||||||
@@ -15,10 +16,10 @@ impl PostEntry {
|
|||||||
self.published_at.format("%B %d, %Y").to_string()
|
self.published_at.format("%B %d, %Y").to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_html(self) -> Self {
|
pub fn to_html(self) -> Result<Self, anyhow::Error> {
|
||||||
Self {
|
match markdown::to_html_with_options(&self.content, &markdown::Options::gfm()) {
|
||||||
content: markdown::to_html(&self.content),
|
Ok(content) => Ok(Self { content, ..self }),
|
||||||
..self
|
Err(e) => anyhow::bail!(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ pub async fn see_post(
|
|||||||
.await
|
.await
|
||||||
.context(format!("Failed to fetch post #{}", post_id))
|
.context(format!("Failed to fetch post #{}", post_id))
|
||||||
.map_err(AppError::unexpected_page)?
|
.map_err(AppError::unexpected_page)?
|
||||||
.to_html();
|
.to_html()
|
||||||
|
.context("Could not render markdown with extension.")?;
|
||||||
let template = PostTemplate { post };
|
let template = PostTemplate { post };
|
||||||
Ok(Html(template.render().unwrap()).into_response())
|
Ok(Html(template.render().unwrap()).into_response())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user