clean code, parse footer metadata
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
philipp 2024-02-16 10:29:30 +01:00
parent a315d69246
commit 33e10185c0
3 changed files with 31 additions and 48 deletions

View File

@ -54,12 +54,12 @@ impl Abschnitt {
builder.new_par(par_id, absatze[0].clone()); builder.new_par(par_id, absatze[0].clone());
} else { } else {
let mut contents = Vec::new(); let mut contents = Vec::new();
for a in &absatze { contents.extend(absatze.iter().cloned());
contents.push(a.clone());
}
builder.new_par(par_id, Content::Item(contents)); builder.new_par(par_id, Content::Item(contents));
} }
ret.handle_metadata(&mut c, builder);
// Skip all UeberschriftTitle and Absatz // Skip all UeberschriftTitle and Absatz
while let Some(child) = c.peek() { while let Some(child) = c.peek() {
if Ueberschrift::test(child, "titel") { if Ueberschrift::test(child, "titel") {
@ -73,29 +73,38 @@ impl Abschnitt {
break; break;
} }
// assert_eq!(c.next(), None); assert_eq!(c.next(), None);
ret.cont = true; ret.cont = true;
ret ret
} }
// There are paragraph-specific meta-data at the top of each xml file. We parse those. When we // There are paragraph-specific meta-data at the top and bottom of each xml file. We parse
// encounter the title "Text" the real content starts, we stop parsing meta data. // those. When we encounter the title "Text" the real content starts, we stop parsing meta
// data.
fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut LawBuilder) { fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut LawBuilder) {
loop { while c.peek().is_some() {
let key = Ueberschrift::parse(c.next().unwrap(), "titel").content; let key = Ueberschrift::parse(c.next().unwrap(), "titel").content;
println!("{key}");
// We are done with meta-data parsing // We are done with meta-data parsing
if key == "Text" { if key == "Text" {
break; break;
} }
let absatz = Absatz::parse( let mut value = String::new();
c.next() while let Some(child) = c.peek() {
.expect("Expected absatz after title in par headers"), if Absatz::test_with_typ(child, "erltext") {
); let absatz = Absatz::parse(c.next().unwrap());
value.push_str(&format!("{}\n", absatz.content));
let value = absatz.content; } else {
break;
}
}
value = value.trim().into();
if value == "" {
panic!("Expected at least on erltext-absatz after title meta-data");
}
// We want ot use this information in our markdown output. // We want ot use this information in our markdown output.
// TODO: Use all metadata, instead of this specific call // TODO: Use all metadata, instead of this specific call
@ -104,7 +113,6 @@ impl Abschnitt {
} }
self.metadata.insert(key, value); self.metadata.insert(key, value);
continue;
} }
} }

View File

@ -46,31 +46,6 @@ impl Liste {
Self { content } Self { content }
} }
pub(crate) fn parse(n: Node) -> Self {
Expect::from(&n).tag("liste");
let mut content = Vec::new();
let mut c = n.children().peekable();
while let Some(child) = c.peek() {
if Ziffernliste::test(child) {
content.push(Ziffernliste::parse(c.next().unwrap()).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));
} else if Absatz::test_with_typ(child, "satz") {
content.push(Content::Text(Absatz::parse(c.next().unwrap()).content));
} else {
break;
}
}
assert_eq!(c.next(), None);
Self { content }
}
pub(crate) fn get_content(&self) -> Content { pub(crate) fn get_content(&self) -> Content {
Content::List(self.content.clone()) Content::List(self.content.clone())
} }

View File

@ -303,17 +303,17 @@ impl Absatz {
pub(crate) fn parse(n: Node) -> Self { pub(crate) fn parse(n: Node) -> Self {
Expect::from(&n).tag("absatz"); Expect::from(&n).tag("absatz");
if let Some(text) = n.text() { let typ = n.attribute("typ").unwrap().into();
Self {
content: text.into(), let mut content = String::new();
typ: n.attribute("typ").unwrap().into(), // Get text from this element + all direct childs
} for c in n.children() {
} else { if let Some(text) = c.text() {
Self { content.push_str(text);
content: String::new(),
typ: n.attribute("typ").unwrap().into(),
} }
} }
Self { content, typ }
} }
} }