diff --git a/src/paragraph/parser/liste.rs b/src/paragraph/parser/liste.rs index bf8e964..4136d5b 100644 --- a/src/paragraph/parser/liste.rs +++ b/src/paragraph/parser/liste.rs @@ -44,20 +44,8 @@ impl Liste { // Parse stuff inside 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 { - content.push(liste.get_content()); - } + 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)); diff --git a/src/paragraph/parser/mod.rs b/src/paragraph/parser/mod.rs index d19adcf..f6dc94c 100644 --- a/src/paragraph/parser/mod.rs +++ b/src/paragraph/parser/mod.rs @@ -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, + sublist: Option>, } 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) -> Self { + let n = c.next().unwrap(); + assert!(Self::test(&n)); let ebene = n.attribute("ebene").unwrap().parse::().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> = 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) } }