This commit is contained in:
philipp 2023-11-06 16:39:57 +01:00
commit 7b8216276b
3 changed files with 36 additions and 7 deletions

View File

@ -1,6 +1,9 @@
use log::debug;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::{
fmt::{self, Display},
sync::Arc,
};
use crate::{overview, par};
@ -77,6 +80,32 @@ impl From<LawBuilder> for Law {
}
}
impl Law {
pub(crate) fn to_md(&self) {
println!("# {}", self.name);
for header in &self.header {
Self::print_md(&header, 2);
}
}
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);
}
}
HeadingContent::Paragraph(p) => {
for par in p {
println!("{} {par}", "#".repeat(level + 1));
}
}
}
}
}
pub(crate) fn contains(classifier_name: &str, instance_name: &str) -> bool {
instance_name
.to_lowercase()
@ -275,6 +304,7 @@ impl LawBuilder {
"New_par: {par};{}",
serde_json::to_string(&content).unwrap()
));
debug!("new_par=par:{par};content:{content:#?}");
if let Some(index) = self.last_header_index {
let section = Section {
@ -314,7 +344,7 @@ impl LawBuilder {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct Section {
pub(crate) symb: String, // §"1", §"2", ...
pub(crate) par_header: Option<String>,
@ -438,7 +468,7 @@ pub(crate) enum Content {
impl Display for Content {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Text(a) => f.write_str(&format!("{a}")),
Self::Text(a) => f.write_str(&format!("{a}\n")),
Self::Item(a) => {
let mut ret = String::new();
for aa in a {

View File

@ -42,8 +42,8 @@ impl From<roxmltree::Error> for Error {
fn main() {
env_logger::init();
let law = LawBuilder::new("MSchG");
let law = LawBuilder::new("ABGB");
println!("{:#?}", law);
law.to_md();
//println!("{:#?}", builder.toc());
}

View File

@ -1,3 +1,4 @@
use log::{error, info};
use roxmltree::Node;
use crate::{
@ -159,8 +160,6 @@ impl Abschnitt {
absatze.push(Content::Text(absatz.content.replace('\u{a0}', " ").clone()));
}
//TODO: Continue here, (2) and (3) is somehow skipped
//There can be as many 'Absätze' as our lovely lawsetter wants
while let Some(child) = c.peek() {
if AbsatzAbs::test(child) {