The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

markdown: use comrak syntect (#393)

* markdown: use comrak syntect

* css: make the code samples look better

It ain't perfect, but it's probably good enough to start with:
https://media.discordapp.net/attachments/188796211543801856/885244826180808754/20210908_15h26m30s_grim.png

Signed-off-by: Christine Dodrill <me@christine.website>
Co-authored-by: Christine Dodrill <me@christine.website>

authored by

Asherah Connor
Christine Dodrill
and committed by
GitHub
425de3f8 cd5cf074

+23 -12
+1 -1
Cargo.toml
··· 11 11 [dependencies] 12 12 color-eyre = "0.5" 13 13 chrono = "0.4" 14 - comrak = "0.12" 14 + comrak = "0.12.1" 15 15 envy = "0.4" 16 16 estimated_read_time = "1" 17 17 futures = "0.3"
+1 -2
css/gruvbox-dark.css
··· 36 36 37 37 .gruvbox-dark pre { 38 38 background-color: #1d2021; 39 - padding: 0; 40 39 border: none 41 40 } 42 41 ··· 235 234 color: #3c3836; 236 235 background-color: #bdae93; 237 236 } 238 - } 237 + }
-2
css/hack.css
··· 30 30 margin: 0; 31 31 } 32 32 pre { 33 - padding: 2rem; 34 - margin: 1.75rem 0; 35 33 background-color: #fff; 36 34 border: 1px solid #ccc; 37 35 overflow: auto;
+5
css/shim.css
··· 37 37 .conversation-chat { 38 38 align-self: center; 39 39 } 40 + 41 + pre { 42 + padding-left: 1em; 43 + padding-right: 1em; 44 + }
+16 -4
src/app/markdown.rs
··· 1 1 use crate::templates::Html; 2 2 use color_eyre::eyre::{Result, WrapErr}; 3 3 use comrak::nodes::{Ast, AstNode, NodeValue}; 4 - use comrak::{format_html, markdown_to_html, parse_document, Arena, ComrakOptions}; 4 + use comrak::plugins::syntect::SyntectAdapter; 5 + use comrak::{ 6 + format_html_with_plugins, markdown_to_html_with_plugins, parse_document, Arena, ComrakOptions, 7 + ComrakPlugins, 8 + }; 9 + use lazy_static::lazy_static; 5 10 use std::cell::RefCell; 6 11 use url::Url; 7 12 13 + lazy_static! { 14 + static ref SYNTECT_ADAPTER: SyntectAdapter<'static> = SyntectAdapter::new("base16-mocha.dark"); 15 + } 16 + 8 17 pub fn render(inp: &str) -> Result<String> { 9 18 let mut options = ComrakOptions::default(); 10 19 ··· 20 29 let arena = Arena::new(); 21 30 let root = parse_document(&arena, inp, &options); 22 31 32 + let mut plugins = ComrakPlugins::default(); 33 + plugins.render.codefence_syntax_highlighter = Some(&*SYNTECT_ADAPTER); 34 + 23 35 iter_nodes(root, &|node| { 24 36 let mut data = node.data.borrow_mut(); 25 37 match &mut data.value { ··· 33 45 node.detach(); 34 46 let mut message = vec![]; 35 47 for child in node.children() { 36 - format_html(child, &options, &mut message)?; 48 + format_html_with_plugins(child, &options, &mut message, &plugins)?; 37 49 } 38 50 let message = std::str::from_utf8(&message)?; 39 - let mut message = markdown_to_html(message, &options); 51 + let mut message = markdown_to_html_with_plugins(message, &options, &plugins); 40 52 crop_letters(&mut message, 3); 41 53 message.drain((message.len() - 5)..); 42 54 let mood = without_first(u.path()); ··· 57 69 })?; 58 70 59 71 let mut html = vec![]; 60 - format_html(root, &options, &mut html).unwrap(); 72 + format_html_with_plugins(root, &options, &mut html, &plugins).unwrap(); 61 73 62 74 String::from_utf8(html).wrap_err("post is somehow invalid UTF-8") 63 75 }
-2
templates/blogpost.rs.html
··· 147 147 @} 148 148 @} 149 149 </script> 150 - 151 - <script src="https://cdn.christine.website/file/christine-static/prism/prism.js"></script> 152 150 @:footer_html()
-1
templates/header.rs.html
··· 59 59 <link rel="stylesheet" href="/css/hack.css" /> 60 60 <link rel="stylesheet" href="/css/gruvbox-dark.css" /> 61 61 <link rel="stylesheet" href="/css/shim.css" /> 62 - <link rel="stylesheet" href="https://cdn.christine.website/file/christine-static/prism/prism.css" /> 63 62 @if Utc::now().month() == 12 || Utc::now().month() == 1 || Utc::now().month() == 2 { <link rel="stylesheet" href="/css/snow.css" /> } 64 63 <link rel="manifest" href="/static/manifest.json" /> 65 64