aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsherah Connor <ashe@kivikakk.ee>2021-09-08 18:17:26 +1000
committerAsherah Connor <ashe@kivikakk.ee>2021-09-08 20:27:50 +1000
commit013abb56ac6e4f18fddb384f4ffd646d3f6bc684 (patch)
treec1241d50204620c02ef0a3eb02bf2c14e5863944
parentdf32d327004a156168eb3d03dc17961a9e4e4531 (diff)
downloadxesite-013abb56ac6e4f18fddb384f4ffd646d3f6bc684.tar.xz
xesite-013abb56ac6e4f18fddb384f4ffd646d3f6bc684.zip
markdown: use comrak syntect
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml2
-rw-r--r--src/app/markdown.rs20
-rw-r--r--templates/blogpost.rs.html2
-rw-r--r--templates/header.rs.html1
5 files changed, 19 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ad2d76a..571e540 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -308,9 +308,9 @@ dependencies = [
[[package]]
name = "comrak"
-version = "0.12.0"
+version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e555945b4dd9dbe376aeec3c701ba248a95b5479124d16fef575cb3483fae062"
+checksum = "ff3c476e1a33eb4df1212a02db79d0f788bbd760901f34f5897644623e0e4e74"
dependencies = [
"clap",
"entities",
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/src/app/markdown.rs b/src/app/markdown.rs
index dbc5ecf..42a8b7e 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-ocean.dark");
+}
+
pub fn render(inp: &str) -> Result<String> {
let mut options = ComrakOptions::default();
@@ -20,6 +29,9 @@ pub fn render(inp: &str) -> Result<String> {
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<String> {
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<String> {
})?;
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 @@
@}
@}
</script>
-
-<script src="https://cdn.christine.website/file/christine-static/prism/prism.js"></script>
@: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
<link rel="stylesheet" href="/css/hack.css" />
<link rel="stylesheet" href="/css/gruvbox-dark.css" />
<link rel="stylesheet" href="/css/shim.css" />
- <link rel="stylesheet" href="https://cdn.christine.website/file/christine-static/prism/prism.css" />
@if Utc::now().month() == 12 || Utc::now().month() == 1 || Utc::now().month() == 2 { <link rel="stylesheet" href="/css/snow.css" /> }
<link rel="manifest" href="/static/manifest.json" />