From acb31c910fb9be1adf40e2445c5a205d91af45bf Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Mon, 29 Apr 2024 15:15:02 -0300 Subject: [PATCH] feat(npf): prototype headings support --- src/convert/npf.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/convert/npf.rs b/src/convert/npf.rs index 41a91db..295699d 100644 --- a/src/convert/npf.rs +++ b/src/convert/npf.rs @@ -13,7 +13,7 @@ pub mod text_formatting; mod objects_post; -use content_blocks::{BlockImage, BlockText, BlockValue}; +use content_blocks::{BlockImage, BlockText, BlockTextSubtype, BlockValue}; use objects::{BlogInfo, Media}; use text_formatting::{FormatTypeBold, FormatTypeItalic, FormatValue}; @@ -84,6 +84,29 @@ impl<'a> TryFrom<&'a Node<'a, RefCell>> for objects::Post { assert_npf_eq_node_text!(&post, &node); Ok(post) } + NodeValue::Heading(h) => { + let mut post = Self::try_from(node.children())?.fold_content(); + let heading = &mut post.content[0]; + if let BlockValue::Text(ref mut t) = heading { + match h.level { + 1 => { + t.subtype = Some(BlockTextSubtype::Heading1); + } + 2 => { + t.subtype = Some(BlockTextSubtype::Heading2); + } + _ => { + let formatting = FormatValue::Bold(FormatTypeBold::from(&t.text)); + if let Some(ref mut f) = &mut t.formatting { + f.push(formatting); + } else { + t.formatting = Some(vec![formatting]); + } + } + }; + }; + Ok(post) + } NodeValue::Strong => { let strong = Self::try_from(node.children())? .fold_content()