allow both paragraphs and headers in same header (displays par 252ff in abgb)
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m56s
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m56s
This commit is contained in:
parent
39f39e49d6
commit
f47f7c83f2
@ -58,15 +58,13 @@ impl Law {
|
||||
|
||||
fn print_md(header: &Heading, level: usize) {
|
||||
println!("{} {}", "#".repeat(level), header);
|
||||
match &header.content {
|
||||
HeadingContent::Heading(h) => {
|
||||
for child in h {
|
||||
Self::print_md(child, level + 1);
|
||||
for content in &header.content {
|
||||
match content {
|
||||
HeadingContent::Heading(h) => {
|
||||
Self::print_md(h, level + 1);
|
||||
}
|
||||
}
|
||||
HeadingContent::Paragraph(p) => {
|
||||
for par in p {
|
||||
println!("{} {par}", "#".repeat(level + 1));
|
||||
HeadingContent::Paragraph(p) => {
|
||||
println!("{} {p}", "#".repeat(level + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,7 +94,7 @@ impl From<LawBuilder> for Law {
|
||||
pub struct Heading {
|
||||
pub name: String, //1. Hauptstück; 3. Theil; ...
|
||||
pub desc: Option<String>,
|
||||
pub content: HeadingContent, // 1. Theil; 1. Subtheil; ...
|
||||
pub content: Vec<HeadingContent>, // 1. Theil; 1. Subtheil; ...
|
||||
}
|
||||
|
||||
impl Display for Heading {
|
||||
@ -111,26 +109,27 @@ impl Display for Heading {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum HeadingContent {
|
||||
Paragraph(Vec<Section>),
|
||||
Heading(Vec<Heading>),
|
||||
Paragraph(Section),
|
||||
Heading(Heading),
|
||||
}
|
||||
|
||||
impl From<ClassifierInstance> for HeadingContent {
|
||||
fn from(value: ClassifierInstance) -> Self {
|
||||
if value.sections.is_empty() {
|
||||
let mut ret = Vec::new();
|
||||
for child in value.children {
|
||||
ret.push(Heading {
|
||||
name: child.borrow().name.clone(),
|
||||
desc: child.borrow().desc.clone(),
|
||||
content: child.borrow().clone().into(),
|
||||
});
|
||||
}
|
||||
impl From<ClassifierInstance> for Vec<HeadingContent> {
|
||||
fn from(value: ClassifierInstance) -> Vec<HeadingContent> {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
Self::Heading(ret)
|
||||
} else {
|
||||
Self::Paragraph(value.sections)
|
||||
for subsection in value.sections {
|
||||
ret.push(HeadingContent::Paragraph(subsection));
|
||||
}
|
||||
|
||||
for child in value.children {
|
||||
ret.push(HeadingContent::Heading(Heading {
|
||||
name: child.borrow().name.clone(),
|
||||
desc: child.borrow().desc.clone(),
|
||||
content: child.borrow().clone().into(),
|
||||
}));
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,6 +226,8 @@ impl LawBuilder {
|
||||
.responsible_classifier(name)
|
||||
.unwrap_or_else(|| panic!("No classifier for '{name}'"));
|
||||
|
||||
debug!("Responsible_class = {responsible_class:#?}");
|
||||
|
||||
let mut heading: ClassifierInstance = name.into();
|
||||
|
||||
if let Some(last_instance) = &self.last_instance {
|
||||
@ -480,12 +481,33 @@ impl Display for Content {
|
||||
}
|
||||
}
|
||||
|
||||
// Content::Item([
|
||||
// ContentPart::Multiple([
|
||||
// ContentPart::Text("(1) Behörden im Sinne...sind:")
|
||||
// ContentPart::List([
|
||||
// ContentPart::Text("1.")
|
||||
// ContentPart::Text("2.")
|
||||
// ])
|
||||
// ])
|
||||
// ])
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use crate::{config::Config, law::Content};
|
||||
|
||||
use super::Law;
|
||||
|
||||
#[test]
|
||||
fn allow_both_paragraphs_and_headers_in_same_header() {
|
||||
let configs = fs::read_dir("./data/configs").expect("No folder with config files");
|
||||
|
||||
for config in configs {
|
||||
let path = format!("{}", config.unwrap().path().display());
|
||||
if path.contains("abgb") {
|
||||
let (_law_id, mut builder, _) = Config::load(&path).unwrap();
|
||||
builder.new_header("Nullter Theil. Einleitung");
|
||||
builder.new_par("§ 1.".into(), Content::Text("My test law text.".into()));
|
||||
builder.new_header("Erster Hauptstück. Einleitung");
|
||||
builder.new_par("§ 252.".into(), Content::Text("My test law text.".into()));
|
||||
|
||||
let law: Law = builder.into();
|
||||
|
||||
let text = format!("{law:#?}");
|
||||
|
||||
assert!(text.contains(" 252."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user