This commit is contained in:
@ -24,7 +24,7 @@ use std::{
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
path::Path,
|
||||
};
|
||||
use tracing::info;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::{
|
||||
law,
|
||||
@ -37,21 +37,23 @@ pub struct Parser {
|
||||
remove: Vec<String>,
|
||||
replace: Vec<(String, String)>,
|
||||
move_para_headers_into_content: bool,
|
||||
pub(crate) par_sign: String,
|
||||
}
|
||||
|
||||
impl Default for Parser {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self::new(String::from("§"))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parser {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
pub fn new(par_sign: String) -> Self {
|
||||
Self {
|
||||
remove: Vec::new(),
|
||||
replace: Vec::new(),
|
||||
move_para_headers_into_content: false,
|
||||
par_sign,
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +145,7 @@ impl Parser {
|
||||
}
|
||||
|
||||
let xml = if self.move_para_headers_into_content {
|
||||
Self::do_move_para_headers_into_content(&xml)
|
||||
self.do_move_para_headers_into_content(&xml)
|
||||
} else {
|
||||
xml
|
||||
};
|
||||
@ -151,11 +153,12 @@ impl Parser {
|
||||
Risdok::from_str(&xml, builder)
|
||||
}
|
||||
|
||||
fn do_move_para_headers_into_content(xml: &str) -> String {
|
||||
fn do_move_para_headers_into_content(&self, xml: &str) -> String {
|
||||
let mut result = String::from(xml);
|
||||
let ueberschrift_regex = Regex::new(
|
||||
"<ueberschrift typ=\"[^\"]*\" ct=\"[^\"]*\" halign=\"[^\"]*\">(§.*?)</ueberschrift>",
|
||||
)
|
||||
let ueberschrift_regex = Regex::new(&format!(
|
||||
"<ueberschrift typ=\"[^\"]*\" ct=\"[^\"]*\" halign=\"[^\"]*\">({}.*?)</ueberschrift>",
|
||||
self.par_sign
|
||||
))
|
||||
.unwrap();
|
||||
let absatz_regex =
|
||||
Regex::new("<absatz typ=\"[^\"]*\" ct=\"[^\"]*\" halign=\"[^\"]*\">").unwrap();
|
||||
@ -179,6 +182,8 @@ impl Parser {
|
||||
// Remove the <ueberschrift> tag from the result string
|
||||
result.replace_range(cap.get(0).unwrap().range(), "");
|
||||
}
|
||||
|
||||
debug!("{result:#?}");
|
||||
result
|
||||
}
|
||||
}
|
||||
@ -216,6 +221,7 @@ mod tests {
|
||||
|
||||
for config in configs {
|
||||
let path = format!("{}", config.unwrap().path().display());
|
||||
println!("Testing {path}");
|
||||
|
||||
let (law_id, mut builder, parser) = Config::load(&path).unwrap();
|
||||
|
||||
|
@ -346,7 +346,8 @@ pub(crate) struct AbsatzAbs {
|
||||
}
|
||||
impl AbsatzAbs {
|
||||
pub(crate) fn test(n: &Node) -> bool {
|
||||
n.tag_name().name() == "absatz" && n.attribute("typ").unwrap() == "abs"
|
||||
n.tag_name().name() == "absatz"
|
||||
&& (n.attribute("typ").unwrap() == "abs" || n.attribute("typ").unwrap() == "erltext")
|
||||
}
|
||||
pub(crate) fn parse(n: Node) -> Self {
|
||||
assert!(Self::test(&n));
|
||||
|
Reference in New Issue
Block a user