summaryrefslogtreecommitdiff
path: root/src/xml
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-02-26 20:55:46 +0100
committerHampusM <hampus@hampusmat.com>2023-02-26 20:55:46 +0100
commitfbaf9c0e7357e9701a072963c59359e35a021a57 (patch)
treeac991a29dfa34306f5fa96c77612d954c7c23f2c /src/xml
parente27700296d3d61254f8d95852457ae769ca8a511 (diff)
feat: add inline equation support
Diffstat (limited to 'src/xml')
-rw-r--r--src/xml/element.rs40
1 files changed, 40 insertions, 0 deletions
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!("<!--{comment}-->"))
+ }
+ }
+ }
+}
+
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Tagged
{
@@ -152,6 +168,30 @@ pub struct Tagged
attributes: Vec<Attribute>,
}
+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::<String>();
+
+ let child_elements = self
+ .child_elements
+ .into_iter()
+ .map(ToString::to_string)
+ .collect::<String>();
+
+ formatter.write_fmt(format_args!("<{name} {attrs}>{child_elements}</{name}>",))
+ }
+}
+
impl Tagged
{
pub fn new<Name, ChildElements, Attrs>(