allow nested lists
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
2024-02-17 20:48:23 +01:00
parent f517459819
commit d3db84c444
11 changed files with 51 additions and 72 deletions

View File

@ -39,10 +39,25 @@ impl Liste {
let mut c = n.next().unwrap().children().peekable();
let mut last_ebene: Option<usize> = None;
// Parse stuff inside <liste>
while let Some(child) = c.peek() {
if Ziffernliste::test(child) {
content.push(Ziffernliste::parse(c.next().unwrap()).get_content());
let liste = Ziffernliste::parse(c.next().unwrap());
let mut already_added = false;
if let Some(last) = last_ebene {
if liste.ebene > last {
let last_list = content.pop().unwrap();
content.push(Content::List(vec![last_list, liste.get_content()]));
already_added = true;
}
}
last_ebene = Some(liste.ebene);
if !already_added {
content.push(liste.get_content());
}
} else if Schlussteil::test(child) {
// 162 Schifffahrtsgesetz show use that a 'schlussteil' can be at the start of a list
content.push(Content::Text(Schlussteil::parse(c.next().unwrap()).content));

View File

@ -148,7 +148,7 @@ impl Listelem {
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct Ziffernliste {
ebene: String,
ebene: usize,
listelems: Vec<Listelem>,
}
impl Ziffernliste {
@ -160,7 +160,7 @@ impl Ziffernliste {
pub(crate) fn parse(n: Node) -> Self {
assert!(Self::test(&n));
let ebene = n.attribute("ebene").unwrap().into();
let ebene = n.attribute("ebene").unwrap().parse::<usize>().unwrap();
let mut listelems = Vec::new();