From 3bb8271a8a533344de92333cd9e30840f83b8a3b Mon Sep 17 00:00:00 2001 From: Austin Rooks Date: Fri, 19 Apr 2024 14:28:11 -0500 Subject: [PATCH] add syntax highlighting --- src/routes/post.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/post.rs b/src/routes/post.rs index 95f059b..471e268 100644 --- a/src/routes/post.rs +++ b/src/routes/post.rs @@ -5,7 +5,7 @@ use crate::{ use axum::extract::Path; use axum::http::HeaderMap; use axum::response::{Html, IntoResponse}; -use comrak::{markdown_to_html, ComrakOptions}; +use comrak::{markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Options, Plugins}; use reqwest::Client; /// A handler function that will load a post, convert it to HTML, and @@ -51,8 +51,12 @@ pub async fn get_blog_post(headers: HeaderMap, Path(post_name): Path) -> }); } + let s = SyntectAdapter::new(Some("base16-ocean.dark")); + let mut plugins = Plugins::default(); + plugins.render.codefence_syntax_highlighter = Some(&s); + // Parse the post's markdown into an html string. - let post_html = markdown_to_html(&body, &ComrakOptions::default()); + let post_html = markdown_to_html_with_plugins(&body, &Options::default(), &plugins); // Add data to the template's context. context.insert("frontmatter", &frontmatter);