From 587094185df846ec1f8029671b2b2b655cb84c56 Mon Sep 17 00:00:00 2001 From: LailaTheElf Date: Tue, 21 Apr 2026 22:10:40 +0200 Subject: [PATCH] fix html rendering --- src/render/parse_md.rs | 119 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/src/render/parse_md.rs b/src/render/parse_md.rs index 2e11290..306414f 100644 --- a/src/render/parse_md.rs +++ b/src/render/parse_md.rs @@ -10,7 +10,7 @@ use crate::render::Template; pub enum Error { NoCurrentEvent, JinjaError(JinjaError), - TemplateNotFound + TemplateNotFound(String) } impl PartialEq for Error { fn eq(&self, other: &Self) -> bool { @@ -73,13 +73,13 @@ impl<'a> Parser<'a> { fn md_preprocessor(&self) -> Result { let mut new = String::with_capacity(self.md.len()); let mut last_match = 0; - let re = Regex::new(r"\{\% *(.*)\((.*)\).*\%\}").unwrap(); + let re = Regex::new(r"\{\% ([^}]*)\(([^}]*)\) \%\}").unwrap(); for caps in re.captures_iter(self.md) { let m = caps.get(0).unwrap(); new.push_str(&self.md[last_match..m.start()]); let template = &caps[1]; let args = &caps[2]; - new.push_str(&self.render_component(template, context! { args => parse_args(args)})?); + new.push_str(&self.render_component(template, parse_args(args))?); last_match = m.end(); } new.push_str(&self.md[last_match..]); @@ -120,8 +120,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("

{content}

")) } else { Err(e) } @@ -134,8 +134,8 @@ impl<'a> Parser<'a> { level => level as u8, id, classes, attrs }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -147,7 +147,7 @@ impl<'a> Parser<'a> { parents => branch, block_quote_kind }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -159,8 +159,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("

{content}

")) } else { Err(e) } @@ -172,7 +172,7 @@ impl<'a> Parser<'a> { parents => branch, container_kind }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -184,8 +184,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(content) } else { Err(e) } @@ -196,8 +196,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("")) } else { Err(e) } @@ -208,8 +208,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("
  • {content}
  • ")) } else { Err(e) } @@ -220,7 +220,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -232,7 +232,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -244,7 +244,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -256,7 +256,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -269,7 +269,7 @@ impl<'a> Parser<'a> { parents => branch, alignments }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -281,8 +281,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -293,8 +293,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -305,8 +305,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -317,7 +317,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -329,7 +329,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -341,7 +341,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -353,7 +353,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -365,7 +365,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -388,8 +388,8 @@ impl<'a> Parser<'a> { parents => branch, link_type, dest_url, title, id, args }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -401,7 +401,7 @@ impl<'a> Parser<'a> { parents => branch, link_type, dest_url, title, id }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -414,7 +414,7 @@ impl<'a> Parser<'a> { parents => branch, metadata_block_kind }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -427,8 +427,8 @@ impl<'a> Parser<'a> { parents => branch, text }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -439,8 +439,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("{content}")) } else { Err(e) } @@ -451,7 +451,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -463,32 +463,32 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) } }) }, - TreeEvent::Html(_) => { + TreeEvent::Html(html) => { self.render_component("Html", context! { - content, + content => html, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(html) } else { Err(e) } }) }, - TreeEvent::InlineHtml(_) => { + TreeEvent::InlineHtml(html) => { self.render_component("InlineHtml", context! { - content, + content => html, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(html) } else { Err(e) } @@ -499,7 +499,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -511,8 +511,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!(" ")) } else { Err(e) } @@ -523,8 +523,8 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { - todo!() + if let Error::TemplateNotFound(_) = e { + Ok(format!("
    ")) } else { Err(e) } @@ -535,7 +535,7 @@ impl<'a> Parser<'a> { content, parents => branch }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -548,7 +548,7 @@ impl<'a> Parser<'a> { parents => branch, checked }).or_else(|e| { - if e == Error::TemplateNotFound { + if let Error::TemplateNotFound(_) = e { todo!() } else { Err(e) @@ -568,7 +568,8 @@ impl<'a> Parser<'a> { }, Err(e) => { match e.kind() { - minijinja::ErrorKind::TemplateNotFound => Err(Error::TemplateNotFound), + minijinja::ErrorKind::TemplateNotFound => + Err(Error::TemplateNotFound(format!("components/{component}"))), _ => Err(Error::JinjaError(e)), } },