aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-01-20 14:06:02 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-01-20 14:06:02 +0100
commit178a9f444b5250a5b76d3d1a98297da8572a05e5 (patch)
treeb545c2f0ee7f04cb4bad7d4a643f681caacab9be
parent5911221d9fca1c1cfb4c9a31ad159d39461e9b7f (diff)
downloadrocket-blog-178a9f444b5250a5b76d3d1a98297da8572a05e5.tar.gz
rocket-blog-178a9f444b5250a5b76d3d1a98297da8572a05e5.tar.bz2
rocket-blog-178a9f444b5250a5b76d3d1a98297da8572a05e5.zip
Add markdown support for posts using comrak.
-rw-r--r--Cargo.toml1
-rw-r--r--src/controllers/posts_controller.rs7
-rw-r--r--src/main.rs1
-rw-r--r--templates/show_post.html2
4 files changed, 10 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index ccbc097..81c4eb3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ r2d2 = "0.8.2"
r2d2-diesel = "1.0.0"
bart = "0.1.4"
bart_derive = "0.1.4"
+comrak = "0.2.5"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
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("/<id>", format = "text/html")]
fn show(id: i32, conn: utils::DbConn) -> utils::Page<ShowPostTemplate> {
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;
diff --git a/templates/show_post.html b/templates/show_post.html
index 9e633cc..0db8981 100644
--- a/templates/show_post.html
+++ b/templates/show_post.html
@@ -5,7 +5,7 @@
{{> post_actions.html }}
</header>
<section class="teaser">
- {{ .body }}
+ {{{ rendered_body() }}}
</section>
{{/ post }}
</article>