diff --git a/src/lib.rs b/src/lib.rs index d4fd7eb..f408efe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,14 +91,14 @@ //! //! ### Highlight //! -//! Element that starts with ">>>\n", followed by optional header that starts with ">> " and ends with a new line, +//! Element that starts with ">>>\n", followed by optional title that starts with ">> " and ends with a new line, //! followed by optional icon specifier that starts with "> " and ends with a new line, followed by body that can //! contain any number of paragraph elements //! //! Example: //! ```text //! >>> -//! >> Header +//! >> Title //! > icon //! body //! @@ -175,11 +175,11 @@ //! ```text //! /// //! // -//! / header +//! / Title //! some random text //! \\ //! // -//! / header +//! / Title //! some random text //! \\ //! \\\ diff --git a/src/nodes/accordion_tab.rs b/src/nodes/accordion_tab.rs index 29864d4..359ad44 100644 --- a/src/nodes/accordion_tab.rs +++ b/src/nodes/accordion_tab.rs @@ -17,8 +17,8 @@ use super::{ #[derive(Debug, PartialEq, Serialize, Clone)] #[serde(tag = "type")] pub enum AccordionTabNodes { - Pargaraph(Paragraph), - Heading(Heading), + P(Paragraph), + H(Heading), Image(Image), ImageGallery(ImageGallery), List(List), @@ -31,8 +31,8 @@ pub enum AccordionTabNodes { impl Display for AccordionTabNodes { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AccordionTabNodes::Pargaraph(node) => write!(f, "{}", node), - AccordionTabNodes::Heading(node) => write!(f, "{}", node), + AccordionTabNodes::P(node) => write!(f, "{}", node), + AccordionTabNodes::H(node) => write!(f, "{}", node), AccordionTabNodes::Image(node) => write!(f, "{}", node), AccordionTabNodes::ImageGallery(node) => write!(f, "{}", node), AccordionTabNodes::List(node) => write!(f, "{}", node), @@ -47,8 +47,8 @@ impl Display for AccordionTabNodes { impl Node for AccordionTabNodes { fn len(&self) -> usize { match self { - AccordionTabNodes::Pargaraph(node) => node.len(), - AccordionTabNodes::Heading(node) => node.len(), + AccordionTabNodes::P(node) => node.len(), + AccordionTabNodes::H(node) => node.len(), AccordionTabNodes::Image(node) => node.len(), AccordionTabNodes::ImageGallery(node) => node.len(), AccordionTabNodes::List(node) => node.len(), @@ -62,13 +62,13 @@ impl Node for AccordionTabNodes { impl From for AccordionTabNodes { fn from(value: Paragraph) -> Self { - Self::Pargaraph(value) + Self::P(value) } } impl From for AccordionTabNodes { fn from(value: Heading) -> Self { - Self::Heading(value) + Self::H(value) } } @@ -116,15 +116,15 @@ impl From for AccordionTabNodes { #[derive(Debug, PartialEq, Serialize, Clone)] pub struct AccordionTab { - pub header: Option, + pub title: Option, pub nodes: Vec, } impl AccordionTab { - pub fn new>(header: Option, nodes: Vec) -> Self { + pub fn new>(title: Option, nodes: Vec) -> Self { Self { nodes, - header: header.map(|s| s.into()), + title: title.map(|s| s.into()), } } } @@ -133,11 +133,11 @@ impl Display for AccordionTab { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "//\n{header}{nodes}\n\\\\", - header = self - .header + "//\n{title}{nodes}\n\\\\", + title = self + .title .as_ref() - .map_or("".to_string(), |header| format!("/ {}\n", header)), + .map_or("".to_string(), |title| format!("/ {}\n", title)), nodes = self .nodes .iter() @@ -184,7 +184,7 @@ impl Branch for AccordionTab { } fn get_outer_token_length(&self) -> usize { - 6 + self.header.as_ref().map_or(0, |header| header.len() + 3) + 6 + self.title.as_ref().map_or(0, |header| header.len() + 3) } fn is_empty(&self) -> bool { @@ -197,11 +197,11 @@ impl Deserializer for AccordionTab { let mut matcher = Matcher::new(input); if let Some(tab) = matcher.get_match("//\n", "\n\\\\", false) { let mut inner_matcher = Matcher::new(tab.body); - let header = inner_matcher + let title = inner_matcher .get_match("/ ", "\n", false) .map(|header| header.body); - return Self::parse_branch(inner_matcher.get_rest(), "\n\n", Self::new(header, vec![])); + return Self::parse_branch(inner_matcher.get_rest(), "\n\n", Self::new(title, vec![])); } None } @@ -227,9 +227,9 @@ mod cfg { #[test] fn test_accordion_tab_deserialize() { assert_eq!( - AccordionTab::deserialize("//\n/ Header\n# Heading\n\\\\\n\n"), + AccordionTab::deserialize("//\n/ Title\n# Heading\n\\\\\n\n"), Some(AccordionTab::new( - Some("Header"), + Some("Title"), vec![Heading::new("Heading", 1).into()] )) ); @@ -260,17 +260,17 @@ mod cfg { #[test] fn test_accordion_tab_len() { assert_eq!( - AccordionTab::new(Some("Header"), vec![Heading::new("Heading", 1).into()]).len(), - 24 + AccordionTab::new(Some("Title"), vec![Heading::new("Heading", 1).into()]).len(), + 23 ); - assert_eq!(AccordionTab::new(Some("Header"), vec![]).len(), 15); + assert_eq!(AccordionTab::new(Some("Title"), vec![]).len(), 14); } #[test] fn test_accordion_tab_serialize() { assert_eq!( - AccordionTab::new(Some("Header"), vec![Heading::new("Heading", 1).into()]).to_string(), - "//\n/ Header\n# Heading\n\\\\" + AccordionTab::new(Some("Title"), vec![Heading::new("Heading", 1).into()]).to_string(), + "//\n/ Title\n# Heading\n\\\\" ); } @@ -282,7 +282,7 @@ mod cfg { #[test] fn with_all_nodes() { let input = r#"// -/ Header +/ Title # hello ```rust @@ -308,7 +308,7 @@ t**b** {{cloudinary_gallery|cloud_name&tag}} \\"#; let tab = AccordionTab::new( - Some("Header"), + Some("Title"), vec![ Heading::new("hello", 1).into(), Code::new("rust", "let a=1;").into(), diff --git a/src/nodes/highlight.rs b/src/nodes/highlight.rs index 67806df..6aec1da 100644 --- a/src/nodes/highlight.rs +++ b/src/nodes/highlight.rs @@ -8,19 +8,19 @@ use super::paragraph::Paragraph; #[derive(Debug, PartialEq, Serialize, Clone)] pub struct Highlight { - pub header: Option, + pub title: Option, pub icon: Option, pub nodes: Vec, } impl Highlight { - pub fn new, I: Into>( - header: Option, + pub fn new, I: Into>( + title: Option, icon: Option, nodes: Vec, ) -> Self { Self { - header: header.map(|header| header.into()), + title: title.map(|title| title.into()), icon: icon.map(|icon| icon.into()), nodes, } @@ -29,8 +29,8 @@ impl Highlight { impl Display for Highlight { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let header = match &self.header { - Some(header) => format!(">> {header}\n"), + let title = match &self.title { + Some(title) => format!(">> {title}\n"), None => String::new(), }; let icon = match &self.icon { @@ -39,13 +39,13 @@ impl Display for Highlight { }; write!( f, - ">>>\n{header}{icon}{}\n>>>", + ">>>\n{title}{icon}{}\n>>>", self.nodes .iter() .map(|node| node.to_string()) .collect::>() .join("\n\n"), - header = header, + title = title, icon = icon, ) } @@ -61,7 +61,7 @@ impl Node for Highlight { self.nodes.iter().map(|node| node.len()).sum::() + delimiter_length + 8 - + self.header.as_ref().map_or(0, |header| header.len() + 4) + + self.title.as_ref().map_or(0, |title| title.len() + 4) + self.icon.as_ref().map_or(0, |icon| icon.len() + 3) } } @@ -71,13 +71,13 @@ impl Deserializer for Highlight { let mut outer_matcher = Matcher::new(input); if let Some(highlight) = outer_matcher.get_match(">>>\n", "\n>>>", false) { let mut matcher = Matcher::new(highlight.body); - let header = matcher + let title = matcher .get_match(">> ", "\n", false) - .map(|header| header.body); + .map(|title| title.body); let icon = matcher.get_match("> ", "\n", false).map(|icon| icon.body); return Some(Self::new( - header, + title, icon, matcher .get_rest() diff --git a/src/nodes/yamd.rs b/src/nodes/yamd.rs index e5ed5b4..a509a5b 100644 --- a/src/nodes/yamd.rs +++ b/src/nodes/yamd.rs @@ -282,11 +282,11 @@ _I_ /// // -/ accordeon tab +/ accordion tab \\ // -/ one more accordeon tab +/ one more accordion tab \\ \\\ @@ -383,8 +383,8 @@ end"#; Embed::new("youtube", "123",).into(), Embed::new("cloudinary_gallery", "cloud_name&tag",).into(), Accordion::new(vec![ - AccordionTab::new(Some("accordeon tab"), vec![]).into(), - AccordionTab::new(Some("one more accordeon tab"), vec![]).into() + AccordionTab::new(Some("accordion tab"), vec![]).into(), + AccordionTab::new(Some("one more accordion tab"), vec![]).into() ]) .into(), Paragraph::new(vec![Text::new("end").into()]).into() @@ -459,8 +459,8 @@ end"#; Embed::new("youtube", "123",).into(), Embed::new("cloudinary_gallery", "cloud_name&tag",).into(), Accordion::new(vec![ - AccordionTab::new(Some("accordeon tab"), vec![]).into(), - AccordionTab::new(Some("one more accordeon tab"), vec![]).into() + AccordionTab::new(Some("accordion tab"), vec![]).into(), + AccordionTab::new(Some("one more accordion tab"), vec![]).into() ]) .into(), Paragraph::new(vec![Text::new("end").into()]).into()