summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-02 19:59:00 +0100
committerHampusM <hampus@hampusmat.com>2023-03-02 19:59:00 +0100
commit743e973e63487c14325c6e8e27884d5366846d2c (patch)
tree6712ac03cb10079f8c1ccf8b612c8be56c8738b0
parentbea6e9cccab30ba915a5d3888a0bd1cd02c9fabd (diff)
fix: informal table use first body row if no head is found
-rw-r--r--src/informal_table.rs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/informal_table.rs b/src/informal_table.rs
index 624118b..a940de4 100644
--- a/src/informal_table.rs
+++ b/src/informal_table.rs
@@ -127,17 +127,7 @@ impl TableGroup
})
.collect::<Result<Vec<_>, _>>()?;
- let head = element
- .child_elements()
- .get_first_tagged_with_name("thead")
- .ok_or(TableGroupError::MissingHead)?
- .child_elements()
- .get_all_tagged_elements_with_name("row")
- .into_iter()
- .map(|row_element| TableRow::from_elements(row_element.child_elements()))
- .collect::<Result<Vec<_>, _>>()?;
-
- let body = element
+ let mut body = element
.child_elements()
.get_first_tagged_with_name("tbody")
.ok_or(TableGroupError::MissingBody)?
@@ -147,6 +137,23 @@ impl TableGroup
.map(|row_element| TableRow::from_elements(row_element.child_elements()))
.collect::<Result<Vec<_>, _>>()?;
+ let head = element
+ .child_elements()
+ .get_first_tagged_with_name("thead")
+ .map_or_else(
+ || Ok(vec![body.remove(0)]),
+ |head_element| {
+ head_element
+ .child_elements()
+ .get_all_tagged_elements_with_name("row")
+ .into_iter()
+ .map(|row_element| {
+ TableRow::from_elements(row_element.child_elements())
+ })
+ .collect::<Result<Vec<_>, _>>()
+ },
+ )?;
+
Ok(Self {
cols,
align,
@@ -169,10 +176,6 @@ pub enum TableGroupError
#[error("Invalid column specification")]
InvalidColumnSpec(#[from] ColumnSpecError),
- /// Missing head element.
- #[error("Missing head")]
- MissingHead,
-
/// Missing body element.
#[error("Missing body")]
MissingBody,