From fbaf9c0e7357e9701a072963c59359e35a021a57 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 26 Feb 2023 20:55:46 +0100 Subject: feat: add inline equation support --- src/xml/element.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/xml') diff --git a/src/xml/element.rs b/src/xml/element.rs index 91e4130..0f44182 100644 --- a/src/xml/element.rs +++ b/src/xml/element.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + #[derive(Debug, PartialEq, Eq, Clone)] pub struct Elements { @@ -144,6 +146,20 @@ pub enum Element Comment(String), } +impl Display for Element +{ + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result + { + match self { + Self::Tagged(tagged) => tagged.fmt(formatter), + Self::Text(text) => text.fmt(formatter), + Self::Comment(comment) => { + formatter.write_fmt(format_args!("")) + } + } + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub struct Tagged { @@ -152,6 +168,30 @@ pub struct Tagged attributes: Vec, } +impl Display for Tagged +{ + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result + { + let name = &self.name; + + let attrs = self + .attributes + .iter() + .map(|attr| { + format!("{}=\"{}\" ", attr.key, String::from_utf8_lossy(&attr.value)) + }) + .collect::(); + + let child_elements = self + .child_elements + .into_iter() + .map(ToString::to_string) + .collect::(); + + formatter.write_fmt(format_args!("<{name} {attrs}>{child_elements}",)) + } +} + impl Tagged { pub fn new( -- cgit v1.2.3-18-g5258