From e43cf4a8f340a2d374ddac95e2e9570c9fece666 Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Fri, 2 Aug 2024 10:34:56 +0200 Subject: [PATCH] Fix links --- src/elements/link.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/elements/link.rs b/src/elements/link.rs index d76db5d..be927a5 100644 --- a/src/elements/link.rs +++ b/src/elements/link.rs @@ -21,13 +21,11 @@ use regex::Regex; use std::ops::Range; use std::rc::Rc; -use super::paragraph::Paragraph; - #[derive(Debug)] pub struct Link { pub(self) location: Token, /// Display content of link - pub(self) display: Paragraph, + pub(self) display: Vec>, /// Url of link pub(self) url: String, } @@ -45,11 +43,9 @@ impl Element for Link { Compiler::sanitize(compiler.target(), self.url.as_str()) ); - result += self - .display - .compile(compiler, document) - .as_ref() - .map(|r| r.as_str())?; + for elem in &self.display { + result += elem.compile(compiler, document)?.as_str(); + } result += ""; Ok(result) @@ -62,13 +58,14 @@ impl Element for Link { } impl ContainerElement for Link { - fn contained(&self) -> &Vec> { &self.display.content } + fn contained(&self) -> &Vec> { &self.display } fn push(&mut self, elem: Box) -> Result<(), String> { if elem.downcast_ref::().is_some() { return Err("Tried to push a link inside of a link".to_string()); } - self.display.push(elem) + self.display.push(elem); + Ok(()) } } @@ -152,7 +149,7 @@ impl RegexRule for LinkRule { ); return reports; } - Ok(paragraph) => *paragraph, + Ok(mut paragraph) => std::mem::replace(&mut paragraph.content, vec![]), } } _ => panic!("Empty link name"), @@ -215,6 +212,7 @@ impl RegexRule for LinkRule { #[cfg(test)] mod tests { + use crate::elements::paragraph::Paragraph; use crate::elements::style::Style; use crate::elements::text::Text; use crate::parser::langparser::LangParser;