This commit is contained in:
@ -60,6 +60,10 @@ impl Absatz {
|
||||
// After a 'absatz' there can be a '<absatz typ="[satz|erltext]"' which should be part of the first absatz
|
||||
// (e.g. 1209 ABGB)
|
||||
content.push(Content::Text(Absatz::parse(c.next().unwrap()).content));
|
||||
} else if child.tag_name().name() == "absatz"
|
||||
&& child.attribute("typ") == Some("abbobj")
|
||||
{
|
||||
content.push(Self::parse_abbobj(c.next().unwrap()));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -71,6 +75,39 @@ impl Absatz {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_abbobj(n: Node) -> Content {
|
||||
Expect::from(&n).tag("absatz").typ("abbobj");
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let mut c = n.children().peekable();
|
||||
|
||||
// skip tab(s)
|
||||
while let Some(child) = c.peek() {
|
||||
if child.tag_name().name() == "tab" {
|
||||
c.next();
|
||||
continue;
|
||||
}
|
||||
|
||||
let binary = c.next().unwrap();
|
||||
|
||||
// TODO: this if should not be necessary...
|
||||
if binary.tag_name().name() != "binary" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut c = binary.children();
|
||||
let src = c.next().unwrap();
|
||||
|
||||
ret.push(Content::Image(src.text().unwrap().into()))
|
||||
}
|
||||
|
||||
if ret.len() == 1 {
|
||||
ret[0].clone()
|
||||
} else {
|
||||
Content::Multi(ret)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse(n: Node) -> Self {
|
||||
Expect::from(&n).tag("absatz");
|
||||
|
||||
|
@ -58,6 +58,8 @@ impl Abschnitt {
|
||||
if AbsatzAbs::test(child) {
|
||||
let (_, absatz) = Absatz::parse_full(&mut c);
|
||||
absatze.push(absatz);
|
||||
} else if Ueberschrift::test(child, "erll") {
|
||||
absatze.push(Ueberschrift::parse_full_erll(&mut c));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Copyright (C) 2024 Philipp Hofer
|
||||
//
|
||||
//
|
||||
// Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
|
||||
// the European Commission - subsequent versions of the EUPL (the "Licence").
|
||||
// You may not use this work except in compliance with the Licence.
|
||||
@ -22,6 +23,7 @@ mod table;
|
||||
use std::{fmt::Display, iter::Peekable};
|
||||
|
||||
use abschnitt::Abschnitt;
|
||||
use liste::Liste;
|
||||
use roxmltree::{Children, Node};
|
||||
|
||||
use crate::{
|
||||
@ -418,6 +420,36 @@ impl Ueberschrift {
|
||||
typ: typ.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_full_erll(n: &mut Peekable<Children>) -> Content {
|
||||
let mut ret = Vec::new();
|
||||
let mut curr = Vec::new();
|
||||
|
||||
// We need at least 1 erll
|
||||
curr.push(Content::Text(
|
||||
Self::parse(n.next().unwrap(), "erll").content,
|
||||
));
|
||||
|
||||
while let Some(child) = &mut n.peek() {
|
||||
if Absatz::test_with_typ(child, "abbobj") {
|
||||
curr.push(Absatz::parse_abbobj(n.next().unwrap()));
|
||||
} else if Liste::test(child) {
|
||||
curr.push(Content::List(Liste::parse_full(n).content));
|
||||
} else if Absatz::test_with_typ(child, "abs") {
|
||||
let (_, absatz) = Absatz::parse_full(n);
|
||||
curr.push(absatz);
|
||||
} else if Ueberschrift::test(child, "erll") {
|
||||
ret.push(Content::Multi(curr));
|
||||
curr = vec![Content::Text(
|
||||
Self::parse(n.next().unwrap(), "erll").content,
|
||||
)];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Content::Multi(ret)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
Reference in New Issue
Block a user