From 00e9473b0f01d04382b73a845e2169c12ff0adbb Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Sat, 2 Mar 2024 21:01:27 +0100 Subject: [PATCH] before another parser implementation --- axum_server/src/post_parser.rs | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/axum_server/src/post_parser.rs b/axum_server/src/post_parser.rs index 6d1f24a..bbda4b8 100644 --- a/axum_server/src/post_parser.rs +++ b/axum_server/src/post_parser.rs @@ -2,11 +2,7 @@ use std::path::Path; use axum::http::StatusCode; use chrono::{DateTime, Utc}; -use comrak::{ - format_html, - nodes::{AstNode, NodeValue}, - parse_document, Arena, Options, -}; +use comrak::{format_html_with_plugins, parse_document, Arena, Options}; use gray_matter::{engine::YAML, Matter}; use serde::{de::DeserializeOwned, Deserialize, Deserializer}; use tokio::fs; @@ -88,25 +84,32 @@ fn parse_html(markdown: &str) -> String { let root = parse_document(&arena, markdown, &options); - fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) - where - F: Fn(&'a AstNode<'a>), - { - f(node); - for c in node.children() { - iter_nodes(c, f); - } - } + // fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) + // where + // F: Fn(&'a AstNode<'a>), + // { + // f(node); + // for c in node.children() { + // iter_nodes(c, f); + // } + // } - iter_nodes(root, &|node| match &mut node.data.borrow_mut().value { - &mut NodeValue::Text(ref mut _text) => { - // let orig = std::mem::replace(text, String::new()); - // *text = orig.replace("my", "your"); - } - _ => (), - }); + // iter_nodes(root, &mut |node| match &mut node.data.borrow_mut().value { + // &mut NodeValue::Text(ref mut _text) => { + // // let orig = std::mem::replace(text, String::new()); + // // *text = orig.replace("my", "your"); + // } + // &mut NodeValue::Image(ref mut img) => { + // let title = img.title; + // let mut fig_caption = Node::new(NodeValue::Text("Figure Caption".into())); + // let mut fig = Node::new(NodeValue::HtmlInline("ahoj".to_string())); + // *node = fig; + // // NodeValue::HtmlInline("".to_string()); + // } + // _ => (), + // }); let mut html = vec![]; - format_html(root, &options, &mut html).unwrap(); + format_html_with_plugins(root, &options, &mut html, &plugins).unwrap(); return String::from_utf8(html).unwrap(); }