clean code, parse footer metadata
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled
This commit is contained in:
parent
a315d69246
commit
33e10185c0
@ -54,12 +54,12 @@ impl Abschnitt {
|
||||
builder.new_par(par_id, absatze[0].clone());
|
||||
} else {
|
||||
let mut contents = Vec::new();
|
||||
for a in &absatze {
|
||||
contents.push(a.clone());
|
||||
}
|
||||
contents.extend(absatze.iter().cloned());
|
||||
builder.new_par(par_id, Content::Item(contents));
|
||||
}
|
||||
|
||||
ret.handle_metadata(&mut c, builder);
|
||||
|
||||
// Skip all UeberschriftTitle and Absatz
|
||||
while let Some(child) = c.peek() {
|
||||
if Ueberschrift::test(child, "titel") {
|
||||
@ -73,29 +73,38 @@ impl Abschnitt {
|
||||
break;
|
||||
}
|
||||
|
||||
// assert_eq!(c.next(), None);
|
||||
assert_eq!(c.next(), None);
|
||||
|
||||
ret.cont = true;
|
||||
ret
|
||||
}
|
||||
|
||||
// There are paragraph-specific meta-data at the top of each xml file. We parse those. When we
|
||||
// encounter the title "Text" the real content starts, we stop parsing meta data.
|
||||
// There are paragraph-specific meta-data at the top and bottom of each xml file. We parse
|
||||
// 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) {
|
||||
loop {
|
||||
while c.peek().is_some() {
|
||||
let key = Ueberschrift::parse(c.next().unwrap(), "titel").content;
|
||||
println!("{key}");
|
||||
|
||||
// We are done with meta-data parsing
|
||||
if key == "Text" {
|
||||
break;
|
||||
}
|
||||
|
||||
let absatz = Absatz::parse(
|
||||
c.next()
|
||||
.expect("Expected absatz after title in par headers"),
|
||||
);
|
||||
|
||||
let value = absatz.content;
|
||||
let mut value = String::new();
|
||||
while let Some(child) = c.peek() {
|
||||
if Absatz::test_with_typ(child, "erltext") {
|
||||
let absatz = Absatz::parse(c.next().unwrap());
|
||||
value.push_str(&format!("{}\n", 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.
|
||||
// TODO: Use all metadata, instead of this specific call
|
||||
@ -104,7 +113,6 @@ impl Abschnitt {
|
||||
}
|
||||
|
||||
self.metadata.insert(key, value);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,31 +46,6 @@ impl Liste {
|
||||
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 {
|
||||
Content::List(self.content.clone())
|
||||
}
|
||||
|
@ -303,17 +303,17 @@ impl Absatz {
|
||||
pub(crate) fn parse(n: Node) -> Self {
|
||||
Expect::from(&n).tag("absatz");
|
||||
|
||||
if let Some(text) = n.text() {
|
||||
Self {
|
||||
content: text.into(),
|
||||
typ: n.attribute("typ").unwrap().into(),
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
content: String::new(),
|
||||
typ: n.attribute("typ").unwrap().into(),
|
||||
let typ = n.attribute("typ").unwrap().into();
|
||||
|
||||
let mut content = String::new();
|
||||
// Get text from this element + all direct childs
|
||||
for c in n.children() {
|
||||
if let Some(text) = c.text() {
|
||||
content.push_str(text);
|
||||
}
|
||||
}
|
||||
|
||||
Self { content, typ }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user