diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/informal_table.rs | 33 |
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, |