refactor: create push_formatting for BlockText
This commit is contained in:
@@ -64,11 +64,7 @@ impl<'a> TryFrom<&'a Node<'a, RefCell<Ast>>> 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<Ast>>> 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());
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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<BlockTextSubtype>,
|
||||
pub text: String,
|
||||
pub formatting: Option<Vec<super::text_formatting::FormatValue>>,
|
||||
pub formatting: Option<Vec<FormatValue>>,
|
||||
pub ident_level: Option<u8>,
|
||||
}
|
||||
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"),
|
||||
|
||||
Reference in New Issue
Block a user