From b1424312a932f345f86a93aba662add645fcf921 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 27 Feb 2023 20:43:28 +0100 Subject: fix: ignore comments in description paragraphs --- src/description.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/description.rs b/src/description.rs index e7cb951..f6e0f70 100644 --- a/src/description.rs +++ b/src/description.rs @@ -1,7 +1,7 @@ //! Reference entry description. use crate::itemized_list::{Error as ItemizedListError, ItemizedList}; use crate::variable_list::{Error as VariableListError, VariableList}; -use crate::xml::element::{Elements, FromElements, Tagged}; +use crate::xml::element::{Element, Elements, FromElements, Tagged}; /// Reference entry description. #[derive(Debug, Clone, PartialEq, Eq)] @@ -171,8 +171,14 @@ impl FromElements for Paragraph { let parts = elements .into_iter() - .map(|element| { - ParagraphPart::from_elements(&Elements::from([element.clone()])) + .filter_map(|element| { + if matches!(element, Element::Comment(_)) { + return None; + } + + Some(ParagraphPart::from_elements(&Elements::from([ + element.clone() + ]))) }) .collect::, _>>()?; @@ -239,7 +245,7 @@ impl FromElements for ParagraphPart let text = elements .get_first_text_element() - .ok_or(Self::Error::InputIsComment)?; + .ok_or(Self::Error::ExpectedTextElement)?; Ok(Self::Text(text.clone())) } @@ -321,9 +327,9 @@ impl ParagraphPart #[derive(Debug, thiserror::Error)] pub enum ParagraphPartError { - /// Input element is a comment. - #[error("Input element is a comment")] - InputIsComment, + /// Expected a text element. + #[error("Expected a text element")] + ExpectedTextElement, /// A input element is a unknown description part. #[error("Input element with name '{0}' is a unknown description part")] -- cgit v1.2.3-18-g5258