From a15a878b87a4891ec856178c151faeaaa1799ad3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 4 Mar 2023 13:18:33 +0100 Subject: feat: add table support --- src/description.rs | 53 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'src/description.rs') diff --git a/src/description.rs b/src/description.rs index e6cd1cd..615b0c2 100644 --- a/src/description.rs +++ b/src/description.rs @@ -1,6 +1,6 @@ //! Reference entry description. -use crate::informal_table::{Error as InformalTableError, InformalTable}; use crate::itemized_list::{Error as ItemizedListError, ItemizedList}; +use crate::table::{Error as TableError, Informal, Table}; use crate::variable_list::{Error as VariableListError, VariableList}; use crate::xml::element::{Element, Elements, FromElements, Tagged}; @@ -97,7 +97,7 @@ impl FromElements for Description .unwrap_or_default(), ))), "informaltable" => Some( - InformalTable::from_elements(part_elem.child_elements()) + Informal::from_elements(part_elem.child_elements()) .map(Part::InformalTable) .map_err(Self::Error::InvalidInformalTable), ), @@ -106,6 +106,11 @@ impl FromElements for Description .map(Part::ItemizedList) .map_err(Self::Error::InvalidItemizedList), ), + "table" => Some( + Table::from_elements(part_elem.child_elements()) + .map(Part::Table) + .map_err(Self::Error::InvalidTable), + ), "title" => None, name => Some(Err(Self::Error::UnknownPartFound(name.to_string()))), }) @@ -136,11 +141,15 @@ pub enum Error /// Invalid informal table. #[error("Invalid informal table")] - InvalidInformalTable(#[source] InformalTableError), + InvalidInformalTable(#[source] TableError), /// Invalid itemized list. #[error("Invalid itemized list")] InvalidItemizedList(#[source] ItemizedListError), + + /// Invalid table. + #[error("Invalid table")] + InvalidTable(#[source] TableError), } /// Description part. @@ -157,10 +166,13 @@ pub enum Part ProgramListing(String), /// Informal table. - InformalTable(InformalTable), + InformalTable(Informal), /// Itemized list. ItemizedList(ItemizedList), + + /// Table. + Table(Table), } /// Reference entry description paragraph. @@ -258,13 +270,16 @@ pub enum ParagraphPart ItemizedList(ItemizedList), /// Informal table part. - InformalTable(InformalTable), + InformalTable(Informal), /// Paragraph part. Paragraph(Paragraph), /// Footnote part. Footnote(Paragraph), + + /// Table part. + Table(Table), } impl FromElements for ParagraphPart @@ -300,11 +315,10 @@ impl ParagraphPart "inlineequation" => Self::InlineEquation, "programlisting" => Self::ProgramListing, "citerefentry" => Self::Entry, - "variablelist" | "itemizedlist" | "informaltable" | "para" | "footnote" => { - |_| { - unreachable!(); - } - } + "variablelist" | "itemizedlist" | "informaltable" | "para" | "footnote" + | "table" => |_| { + unreachable!(); + }, _ => { return Err(::Error::UnknownPart( tagged_element.name().to_string(), @@ -341,10 +355,8 @@ impl ParagraphPart } if tagged_element.name() == "informaltable" { - let informal_table = InformalTable::from_elements( - tagged_element.child_elements(), - ) - .map_err(|err| ParagraphPartError::InvalidInformalTable(Box::new(err)))?; + let informal_table = Informal::from_elements(tagged_element.child_elements()) + .map_err(|err| ParagraphPartError::InvalidInformalTable(Box::new(err)))?; return Ok(Self::InformalTable(informal_table)); } @@ -373,6 +385,13 @@ impl ParagraphPart )); } + if tagged_element.name() == "table" { + let table = Table::from_elements(tagged_element.child_elements()) + .map_err(|err| ParagraphPartError::InvalidInformalTable(Box::new(err)))?; + + return Ok(Self::Table(table)); + } + let text_element = tagged_element .child_elements() .get_first_text_element() @@ -412,7 +431,7 @@ pub enum ParagraphPartError /// Invalid informal table. #[error("Invalid informal table")] - InvalidInformalTable(#[source] Box), + InvalidInformalTable(#[source] Box), /// Invalid paragraph. #[error("Invalid paragraph")] @@ -421,4 +440,8 @@ pub enum ParagraphPartError /// Invalid footnote. #[error("Invalid footnote")] InvalidFootnote(#[source] Box), + + /// Invalid table. + #[error("Invalid table")] + InvalidTable(#[source] Box), } -- cgit v1.2.3-18-g5258