From 06d4bf7d69e7f58f51c49e6f3a712c50412b7ceb Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 7 May 2022 14:32:04 +0000 Subject: src/app/markdown: no-js xeblog-conv support Thanks to the meddling of @fasterthanlime, I now use lol_html[0] to parse the elements on the server side instead of on the client side as an HTML custom element. I will be using this strategy in the future to expand my blog's functionality and make the christine dot website cinematic universe stronger. Signed-off-by: Xe Iaso --- src/app/markdown.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app/markdown.rs b/src/app/markdown.rs index 6b37b67..f44236d 100644 --- a/src/app/markdown.rs +++ b/src/app/markdown.rs @@ -7,6 +7,7 @@ use comrak::{ ComrakPlugins, }; use lazy_static::lazy_static; +use lol_html::{rewrite_str, element, RewriteStrSettings, html_content::ContentType}; use std::cell::RefCell; use url::Url; @@ -71,7 +72,35 @@ pub fn render(inp: &str) -> Result { let mut html = vec![]; format_html_with_plugins(root, &options, &mut html, &plugins).unwrap(); - String::from_utf8(html).wrap_err("post is somehow invalid UTF-8") + let html = String::from_utf8(html).wrap_err("post is somehow invalid UTF-8")?; + + let html = rewrite_str(&html, RewriteStrSettings{ + element_content_handlers: vec![ + element!("xeblog-conv", |el| { + let name = el.get_attribute("name").expect("wanted xeblog-conv to contain name"); + let name_lower = name.clone().to_lowercase(); + let mood = el.get_attribute("mood").expect("wanted xeblog-conv to contain mood"); + + el.before(&format!(r#" +
+
+ + + + {name} is {mood} + +
+
<{name}> "#), ContentType::Html); + el.after("
", ContentType::Html); + + el.remove_and_keep_content(); + Ok(()) + }) + ], + ..RewriteStrSettings::default() + }).unwrap(); + + Ok(html) } fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) -> Result<()> -- cgit v1.2.3