From f53069043adb35e5336e8694f49af57000951b9c Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Mon, 1 Apr 2024 16:59:59 -0300 Subject: [PATCH] feat: primitive quoteblock support --- src/convert.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/convert.rs b/src/convert.rs index 0edec33..4842258 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -77,6 +77,60 @@ pub fn to_tumblr_npf<'a>(ast: &'a Node<'a, RefCell>) -> Result npf.borrow_mut().content.push(ContentType::Text(block)); } + NodeValue::BlockQuote => { + let block_quote = to_tumblr_npf(node); + let final_block = RefCell::new(content_types::Text::new()); + + block_quote + .unwrap() + .borrow_mut() + .content + .iter_mut() + .for_each(|b| { + if let ContentType::Text(t) = b { + let mut fb = final_block.borrow_mut(); + let text_len = fb.text.chars().count(); + + if let Some(formattings) = &t.formatting { + for formatting in formattings { + match fb.formatting { + Some(ref mut v) => v.push(Formatting { + start: text_len + formatting.start, + end: text_len + formatting.end, + ..formatting.clone() + }), + None => { + fb.formatting = Some(vec![Formatting { + start: text_len + formatting.start, + end: text_len + formatting.end, + ..formatting.clone() + }]); + } + } + } + } + fb.text.push_str(&format!("{}\n\n", &t.text)); + } else { + } + }); + + println!("{node:#?}"); + println!("{:#?}", final_block.borrow()); + /* + block_quote + .unwrap() + .borrow_mut() + .content + .iter_mut() + .map(|b| { + if let ContentType::Text(ref mut t) = b { + t.subtype = Some(Subtypes::Indented); + } + b + }) + .for_each(|b| npf.borrow_mut().content.push(b.clone())); + */ + } _ => (), });