From 656ca92bc5958752d6a12e2a659fe17809fe5e86 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 1 Mar 2023 21:50:13 +0100 Subject: feat: add informal table support --- src/description.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/description.rs') diff --git a/src/description.rs b/src/description.rs index f6e0f70..5d0cb1f 100644 --- a/src/description.rs +++ b/src/description.rs @@ -1,4 +1,5 @@ //! Reference entry description. +use crate::informal_table::{Error as InformalTableError, InformalTable}; use crate::itemized_list::{Error as ItemizedListError, ItemizedList}; use crate::variable_list::{Error as VariableListError, VariableList}; use crate::xml::element::{Element, Elements, FromElements, Tagged}; @@ -95,6 +96,11 @@ impl FromElements for Description .cloned() .unwrap_or_default(), ))), + "informaltable" => Some( + InformalTable::from_elements(part_elem.child_elements()) + .map(Part::InformalTable) + .map_err(Self::Error::InvalidInformalTable), + ), "title" => None, name => Some(Err(Self::Error::UnknownPartFound(name.to_string()))), }) @@ -122,6 +128,10 @@ pub enum Error /// Invalid variable list. #[error("Invalid variable list")] InvalidVariableList(#[source] VariableListError), + + /// Invalid informal table. + #[error("Invalid informal table")] + InvalidInformalTable(#[source] InformalTableError), } /// Description part. @@ -136,6 +146,9 @@ pub enum Part /// Program listing. ProgramListing(String), + + /// Informal table. + InformalTable(InformalTable), } /// Reference entry description paragraph. @@ -231,6 +244,9 @@ pub enum ParagraphPart /// Itemized list part. ItemizedList(ItemizedList), + + /// Informal table part. + InformalTable(InformalTable), } impl FromElements for ParagraphPart @@ -266,7 +282,7 @@ impl ParagraphPart "inlineequation" => Self::InlineEquation, "programlisting" => Self::ProgramListing, "citerefentry" => Self::Entry, - "variablelist" | "itemizedlist" => |_| { + "variablelist" | "itemizedlist" | "informaltable" => |_| { unreachable!(); }, _ => { @@ -304,6 +320,15 @@ impl ParagraphPart return Ok(Self::ItemizedList(itemized_list)); } + if tagged_element.name() == "informaltable" { + let informal_table = InformalTable::from_elements( + tagged_element.child_elements(), + ) + .map_err(|err| ParagraphPartError::InvalidInformalTable(Box::new(err)))?; + + return Ok(Self::InformalTable(informal_table)); + } + if tagged_element.name() == "inlineequation" { return Ok(Self::InlineEquation( tagged_element @@ -350,4 +375,8 @@ pub enum ParagraphPartError /// Invalid itemized list. #[error("Invalid itemized list")] InvalidItemizedList(#[from] ItemizedListError), + + /// Invalid informal table. + #[error("Invalid informal table")] + InvalidInformalTable(#[source] Box), } -- cgit v1.2.3-18-g5258