summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-02-27 20:43:28 +0100
committerHampusM <hampus@hampusmat.com>2023-02-27 20:43:28 +0100
commitb1424312a932f345f86a93aba662add645fcf921 (patch)
treef2caca17fb8021dc41226de5ff0e7f33b35db1ac
parent8185ac7f4c466eaac178f1e4e8f1d3f7ef1bb49b (diff)
fix: ignore comments in description paragraphs
-rw-r--r--src/description.rs20
1 files 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::<Result<Vec<_>, _>>()?;
@@ -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")]