From 178a9f444b5250a5b76d3d1a98297da8572a05e5 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 20 Jan 2018 14:06:02 +0100 Subject: Add markdown support for posts using comrak. --- src/controllers/posts_controller.rs | 7 +++++++ src/main.rs | 1 + 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index 47f9ca1..aca9d13 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -1,3 +1,4 @@ +use comrak::{markdown_to_html, ComrakOptions}; use rocket::request::Form; use rocket::response::{Flash, Redirect}; use utils; @@ -35,6 +36,12 @@ pub struct ShowPostTemplate { implement_responder_for!(ShowPostTemplate); +impl ShowPostTemplate { + pub fn rendered_body(&self) -> String { + markdown_to_html(&self.post.body, &ComrakOptions::default()) + } +} + #[get("/", format = "text/html")] fn show(id: i32, conn: utils::DbConn) -> utils::Page { let p = ::models::Post::get(id, conn); diff --git a/src/main.rs b/src/main.rs index af3063a..88aa160 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ #[macro_use] extern crate diesel; #[macro_use] extern crate serde_derive; +extern crate comrak; extern crate dotenv; extern crate r2d2; extern crate r2d2_diesel; -- cgit v1.2.3