diff --git a/src/law.rs b/src/law.rs index ae6669e..a624eaa 100644 --- a/src/law.rs +++ b/src/law.rs @@ -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 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, @@ -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 { diff --git a/src/main.rs b/src/main.rs index 2898355..1a644fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,8 +42,8 @@ impl From 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()); } diff --git a/src/par/parser.rs b/src/par/parser.rs index 06e09cf..afb283f 100644 --- a/src/par/parser.rs +++ b/src/par/parser.rs @@ -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) {