diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 304852c..7455e98 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -8,6 +8,7 @@ use crate::{ use super::{ hyperlink::analyze_hyperlink, run::{analyze_run, analyze_run_properties}, + style::analyze_style, }; pub fn get_paragraph_properties(properties: &ParagraphProperty) -> Vec { @@ -17,6 +18,20 @@ pub fn get_paragraph_properties(properties: &ParagraphProperty) -> Vec { props.push(format!("text-align: {}", alignment.val)); }; + if let Some(style) = properties.style.as_ref() { + unsafe { + if let Some(style) = crate::state::STYLE_MAP.get(&style.val) { + if let Some(based_on) = style.based_on.as_ref() { + if let Some(based_on) = crate::state::STYLE_MAP.get(&based_on.val) { + props.append(&mut analyze_style(&based_on)); + } + } + + props.append(&mut analyze_style(&style)); + } + } + } + props } diff --git a/src/parser/style.rs b/src/parser/style.rs index d537a26..9103147 100644 --- a/src/parser/style.rs +++ b/src/parser/style.rs @@ -1,4 +1,4 @@ -use docx_rs::{RunProperty, Style}; +use docx_rs::{ParagraphProperty, RunProperty, Style}; fn analyze_run_properties(run_properties: &RunProperty) -> Vec { let mut accumulator: Vec = vec![]; @@ -15,12 +15,12 @@ fn analyze_run_properties(run_properties: &RunProperty) -> Vec { accumulator.push("text-decoration: underline".to_owned()); }; - if run_properties.sz.is_some() { - accumulator.push(format!( - "font-size: {}px", - run_properties.sz.as_ref().unwrap().val - )); - }; + // if run_properties.sz.is_some() { + // accumulator.push(format!( + // "font-size: {}px", + // run_properties.sz.as_ref().unwrap().val + // )); + // }; if run_properties.strike.is_some() { accumulator.push("text-decoration: line-through".to_owned()); @@ -30,6 +30,29 @@ fn analyze_run_properties(run_properties: &RunProperty) -> Vec { accumulator.push("visibility: hidden".to_owned()); }; + if let Some(color) = &run_properties.color.as_ref() { + let value = &color.val; + if value.len().eq(&6) || value.len().eq(&8) { + if let Ok(_) = u32::from_str_radix(&value, 16) { + accumulator.push(format!("color: #{}", value)); + } else { + accumulator.push(format!("color: {}", value)); + } + } else { + accumulator.push(format!("color: {}", value)); + } + } + + accumulator +} + +pub fn analyze_paragraph_properties(properties: &ParagraphProperty) -> Vec { + let mut accumulator: Vec = vec![]; + + if let Some(alignment) = &properties.alignment.as_ref() { + accumulator.push(format!("text-align: {}", alignment.val)); + }; + accumulator } @@ -37,6 +60,7 @@ pub fn analyze_style(style: &Style) -> Vec { let mut accumulator: Vec = vec![]; accumulator.append(&mut analyze_run_properties(&style.run_property)); + accumulator.append(&mut analyze_paragraph_properties(&style.paragraph_property)); return accumulator; }