diff --git a/Cargo.toml b/Cargo.toml index 51aef93..0f451d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/Xe/site" [dependencies] color-eyre = "0.5" chrono = "0.4" -comrak = "0.12" +comrak = "0.12.1" envy = "0.4" estimated_read_time = "1" futures = "0.3" diff --git a/css/gruvbox-dark.css b/css/gruvbox-dark.css index f3478df..974ff10 100644 --- a/css/gruvbox-dark.css +++ b/css/gruvbox-dark.css @@ -36,7 +36,6 @@ .gruvbox-dark pre { background-color: #1d2021; - padding: 0; border: none } @@ -235,4 +234,4 @@ color: #3c3836; background-color: #bdae93; } -} \ No newline at end of file +} diff --git a/css/hack.css b/css/hack.css index cbbc496..eb4281f 100644 --- a/css/hack.css +++ b/css/hack.css @@ -30,8 +30,6 @@ fieldset { margin: 0; } pre { - padding: 2rem; - margin: 1.75rem 0; background-color: #fff; border: 1px solid #ccc; overflow: auto; diff --git a/css/shim.css b/css/shim.css index 7a32d9a..339c036 100644 --- a/css/shim.css +++ b/css/shim.css @@ -37,3 +37,8 @@ img { .conversation-chat { align-self: center; } + +pre { + padding-left: 1em; + padding-right: 1em; +} diff --git a/src/app/markdown.rs b/src/app/markdown.rs index dbc5ecf..6b37b67 100644 --- a/src/app/markdown.rs +++ b/src/app/markdown.rs @@ -1,10 +1,19 @@ use crate::templates::Html; use color_eyre::eyre::{Result, WrapErr}; use comrak::nodes::{Ast, AstNode, NodeValue}; -use comrak::{format_html, markdown_to_html, parse_document, Arena, ComrakOptions}; +use comrak::plugins::syntect::SyntectAdapter; +use comrak::{ + format_html_with_plugins, markdown_to_html_with_plugins, parse_document, Arena, ComrakOptions, + ComrakPlugins, +}; +use lazy_static::lazy_static; use std::cell::RefCell; use url::Url; +lazy_static! { + static ref SYNTECT_ADAPTER: SyntectAdapter<'static> = SyntectAdapter::new("base16-mocha.dark"); +} + pub fn render(inp: &str) -> Result { let mut options = ComrakOptions::default(); @@ -20,6 +29,9 @@ pub fn render(inp: &str) -> Result { let arena = Arena::new(); let root = parse_document(&arena, inp, &options); + let mut plugins = ComrakPlugins::default(); + plugins.render.codefence_syntax_highlighter = Some(&*SYNTECT_ADAPTER); + iter_nodes(root, &|node| { let mut data = node.data.borrow_mut(); match &mut data.value { @@ -33,10 +45,10 @@ pub fn render(inp: &str) -> Result { node.detach(); let mut message = vec![]; for child in node.children() { - format_html(child, &options, &mut message)?; + format_html_with_plugins(child, &options, &mut message, &plugins)?; } let message = std::str::from_utf8(&message)?; - let mut message = markdown_to_html(message, &options); + let mut message = markdown_to_html_with_plugins(message, &options, &plugins); crop_letters(&mut message, 3); message.drain((message.len() - 5)..); let mood = without_first(u.path()); @@ -57,7 +69,7 @@ pub fn render(inp: &str) -> Result { })?; let mut html = vec![]; - format_html(root, &options, &mut html).unwrap(); + format_html_with_plugins(root, &options, &mut html, &plugins).unwrap(); String::from_utf8(html).wrap_err("post is somehow invalid UTF-8") } diff --git a/templates/blogpost.rs.html b/templates/blogpost.rs.html index a4d01be..808c873 100644 --- a/templates/blogpost.rs.html +++ b/templates/blogpost.rs.html @@ -147,6 +147,4 @@ @} @} - - @:footer_html() diff --git a/templates/header.rs.html b/templates/header.rs.html index bc501b9..399c7d0 100644 --- a/templates/header.rs.html +++ b/templates/header.rs.html @@ -59,7 +59,6 @@ la budza pu cusku lu - @if Utc::now().month() == 12 || Utc::now().month() == 1 || Utc::now().month() == 2 { }