This commit is contained in:
parent
0da0256efa
commit
2d8314f839
@ -44,20 +44,8 @@ impl Liste {
|
||||
// Parse stuff inside <liste>
|
||||
while let Some(child) = c.peek() {
|
||||
if Ziffernliste::test(child) {
|
||||
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::Multi(vec![last_list, liste.get_content()]));
|
||||
already_added = true;
|
||||
}
|
||||
}
|
||||
|
||||
last_ebene = Some(liste.ebene);
|
||||
if !already_added {
|
||||
let liste = Ziffernliste::parse(&mut c);
|
||||
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));
|
||||
|
@ -19,8 +19,10 @@ mod abschnitt;
|
||||
mod liste;
|
||||
mod table;
|
||||
|
||||
use std::iter::Peekable;
|
||||
|
||||
use abschnitt::Abschnitt;
|
||||
use roxmltree::Node;
|
||||
use roxmltree::{Children, Node};
|
||||
|
||||
use crate::{
|
||||
law::{Content, LawBuilder},
|
||||
@ -150,6 +152,7 @@ impl Listelem {
|
||||
pub(crate) struct Ziffernliste {
|
||||
ebene: usize,
|
||||
listelems: Vec<Listelem>,
|
||||
sublist: Option<Box<Ziffernliste>>,
|
||||
}
|
||||
impl Ziffernliste {
|
||||
pub(crate) fn test(n: &Node) -> bool {
|
||||
@ -157,7 +160,16 @@ impl Ziffernliste {
|
||||
["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));
|
||||
|
||||
let ebene = n.attribute("ebene").unwrap().parse::<usize>().unwrap();
|
||||
@ -168,7 +180,22 @@ impl Ziffernliste {
|
||||
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 {
|
||||
@ -181,6 +208,12 @@ impl Ziffernliste {
|
||||
)));
|
||||
}
|
||||
|
||||
if let Some(sublist) = &self.sublist {
|
||||
let sublist = *sublist.clone();
|
||||
|
||||
elems.push(sublist.get_content());
|
||||
}
|
||||
|
||||
Content::List(elems)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user