diff --git a/src/convert/npf.rs b/src/convert/npf.rs index a8cfa54..563cc1d 100644 --- a/src/convert/npf.rs +++ b/src/convert/npf.rs @@ -64,11 +64,7 @@ impl<'a> TryFrom<&'a Node<'a, RefCell>> for objects::Post { .for_each_content(|c| { if let BlockValue::Text(ref mut t) = c { let format = FormatValue::Bold(FormatTypeBold::from(&t.text)); - if let Some(ref mut f) = t.formatting { - f.push(format); - } else { - t.formatting = Some(vec![format]); - } + t.push_formatting(format); t.text = String::from(t.text.trim()); } }) @@ -82,11 +78,7 @@ impl<'a> TryFrom<&'a Node<'a, RefCell>> for objects::Post { .for_each_content(|c| { if let BlockValue::Text(ref mut t) = c { let format = FormatValue::Italic(FormatTypeItalic::from(&t.text)); - if let Some(ref mut f) = t.formatting { - f.push(format); - } else { - t.formatting = Some(vec![format]); - } + t.push_formatting(format); t.text = String::from(t.text.trim()); } }) diff --git a/src/convert/npf/content_blocks.rs b/src/convert/npf/content_blocks.rs index f927511..120dd5d 100644 --- a/src/convert/npf/content_blocks.rs +++ b/src/convert/npf/content_blocks.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, str::FromStr}; use serde::{Deserialize, Serialize}; -use super::{attributions, objects}; +use super::{attributions, objects, text_formatting::FormatValue}; #[derive(Debug, Deserialize, Serialize, Clone)] #[serde(untagged)] @@ -44,13 +44,20 @@ pub struct BlockText { r#type: String, pub subtype: Option, pub text: String, - pub formatting: Option>, + pub formatting: Option>, pub ident_level: Option, } impl BlockText { pub fn new(value: &str) -> Self { Self::from(value) } + pub fn push_formatting(&mut self, format: FormatValue) { + if let Some(ref mut f) = self.formatting { + f.push(format); + } else { + self.formatting = Some(vec![format]); + } + } fn default() -> Self { Self { r#type: String::from("text"),