push
Some checks failed
CI/CD Pipeline / test (push) Failing after 1m41s

This commit is contained in:
philipp 2024-02-17 21:16:41 +01:00
parent 0da0256efa
commit 2d8314f839
2 changed files with 38 additions and 17 deletions

View File

@ -44,20 +44,8 @@ impl Liste {
// Parse stuff inside <liste> // Parse stuff inside <liste>
while let Some(child) = c.peek() { while let Some(child) = c.peek() {
if Ziffernliste::test(child) { if Ziffernliste::test(child) {
let liste = Ziffernliste::parse(c.next().unwrap()); let liste = Ziffernliste::parse(&mut c);
let mut already_added = false;
if let Some(last) = last_ebene {
if liste.ebene > last {
let last_list = content.pop().unwrap();
content.push(Content::Multi(vec![last_list, liste.get_content()]));
already_added = true;
}
}
last_ebene = Some(liste.ebene);
if !already_added {
content.push(liste.get_content()); content.push(liste.get_content());
}
} else if Schlussteil::test(child) { } else if Schlussteil::test(child) {
// 162 Schifffahrtsgesetz show use that a 'schlussteil' can be at the start of a list // 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)); content.push(Content::Text(Schlussteil::parse(c.next().unwrap()).content));

View File

@ -19,8 +19,10 @@ mod abschnitt;
mod liste; mod liste;
mod table; mod table;
use std::iter::Peekable;
use abschnitt::Abschnitt; use abschnitt::Abschnitt;
use roxmltree::Node; use roxmltree::{Children, Node};
use crate::{ use crate::{
law::{Content, LawBuilder}, law::{Content, LawBuilder},
@ -150,6 +152,7 @@ impl Listelem {
pub(crate) struct Ziffernliste { pub(crate) struct Ziffernliste {
ebene: usize, ebene: usize,
listelems: Vec<Listelem>, listelems: Vec<Listelem>,
sublist: Option<Box<Ziffernliste>>,
} }
impl Ziffernliste { impl Ziffernliste {
pub(crate) fn test(n: &Node) -> bool { pub(crate) fn test(n: &Node) -> bool {
@ -157,7 +160,16 @@ impl Ziffernliste {
["ziffernliste", "aufzaehlung", "literaliste", "strichliste"].contains(&n.tag_name().name()) ["ziffernliste", "aufzaehlung", "literaliste", "strichliste"].contains(&n.tag_name().name())
} }
pub(crate) fn parse(n: Node) -> Self { pub(crate) fn test_with_level(n: &Node, level: usize) -> bool {
match n.attribute("ebene") {
Some(ebene) => Self::test(n) && ebene == level.to_string(),
None => false,
}
}
pub(crate) fn parse(c: &mut Peekable<Children>) -> Self {
let n = c.next().unwrap();
assert!(Self::test(&n)); assert!(Self::test(&n));
let ebene = n.attribute("ebene").unwrap().parse::<usize>().unwrap(); let ebene = n.attribute("ebene").unwrap().parse::<usize>().unwrap();
@ -168,7 +180,22 @@ impl Ziffernliste {
listelems.push(Listelem::parse(child)); listelems.push(Listelem::parse(child));
} }
Self { ebene, listelems } // If next element is ebene + 1 -> part of this list
let mut sublist: Option<Box<Ziffernliste>> = None;
while let Some(child) = c.peek() {
if Ziffernliste::test_with_level(child, ebene + 1) {
sublist = Some(Box::new(Ziffernliste::parse(c)));
} else {
break;
}
}
Self {
ebene,
listelems,
sublist,
}
} }
pub(crate) fn get_content(&self) -> Content { pub(crate) fn get_content(&self) -> Content {
@ -181,6 +208,12 @@ impl Ziffernliste {
))); )));
} }
if let Some(sublist) = &self.sublist {
let sublist = *sublist.clone();
elems.push(sublist.get_content());
}
Content::List(elems) Content::List(elems)
} }
} }