feat(elements): cleanup and minor refactor
This commit is contained in:
parent
c1465a6d77
commit
9bc260627b
20 changed files with 802 additions and 835 deletions
|
|
@ -1,5 +1,12 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use nom::{
|
||||
combinator::{peek, verify},
|
||||
IResult,
|
||||
};
|
||||
|
||||
use crate::parsers::{line, take_lines_while};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[cfg_attr(feature = "ser", derive(serde::Serialize))]
|
||||
|
|
@ -34,3 +41,35 @@ impl TableRow {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_table_el(input: &str) -> IResult<&str, &str> {
|
||||
let (input, _) = peek(verify(line, |s: &str| {
|
||||
let s = s.trim();
|
||||
s.starts_with("+-") && s.as_bytes().iter().all(|&c| c == b'+' || c == b'-')
|
||||
}))(input)?;
|
||||
|
||||
take_lines_while(|line| line.starts_with('|') || line.starts_with('+'))(input)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_table_el_() {
|
||||
assert_eq!(
|
||||
parse_table_el(
|
||||
r#"+---+
|
||||
| |
|
||||
+---+
|
||||
|
||||
"#
|
||||
),
|
||||
Ok((
|
||||
r#"
|
||||
"#,
|
||||
r#"+---+
|
||||
| |
|
||||
+---+
|
||||
"#
|
||||
))
|
||||
);
|
||||
assert!(parse_table_el("").is_err());
|
||||
assert!(parse_table_el("+----|---").is_err());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue