summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/description.rs14
-rw-r--r--src/xml/element.rs40
2 files changed, 54 insertions, 0 deletions
diff --git a/src/description.rs b/src/description.rs
index 31eff1e..e436e40 100644
--- a/src/description.rs
+++ b/src/description.rs
@@ -201,6 +201,9 @@ pub enum ParagraphPart
/// Code part.
Code(String),
+ /// Inline equation part.
+ InlineEquation(String),
+
/// Reference entry citation part.
Entry(String),
@@ -241,6 +244,7 @@ impl ParagraphPart
"parameter" => Self::Parameter,
"emphasis" => Self::Emphasis,
"code" => Self::Code,
+ "inlineequation" => Self::InlineEquation,
"citerefentry" => Self::Entry,
"variablelist" | "itemizedlist" => |_| {
unreachable!();
@@ -280,6 +284,16 @@ impl ParagraphPart
return Ok(Self::ItemizedList(itemized_list));
}
+ if tagged_element.name() == "inlineequation" {
+ return Ok(Self::InlineEquation(
+ tagged_element
+ .child_elements()
+ .into_iter()
+ .map(ToString::to_string)
+ .collect::<String>(),
+ ));
+ }
+
let text_element = tagged_element
.child_elements()
.get_first_text_element()
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>(