Skip to content

Commit

Permalink
header - title
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurk committed Nov 4, 2023
1 parent 60720bd commit f39ca8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -175,11 +175,11 @@
//! ```text
//! ///
//! //
//! / header
//! / Title
//! some random text
//! \\
//! //
//! / header
//! / Title
//! some random text
//! \\
//! \\\
Expand Down
24 changes: 12 additions & 12 deletions src/nodes/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use super::paragraph::Paragraph;

#[derive(Debug, PartialEq, Serialize, Clone)]
pub struct Highlight {
pub header: Option<String>,
pub title: Option<String>,
pub icon: Option<String>,
pub nodes: Vec<Paragraph>,
}

impl Highlight {
pub fn new<H: Into<String>, I: Into<String>>(
header: Option<H>,
pub fn new<T: Into<String>, I: Into<String>>(
title: Option<T>,
icon: Option<I>,
nodes: Vec<Paragraph>,
) -> Self {
Self {
header: header.map(|header| header.into()),
title: title.map(|title| title.into()),
icon: icon.map(|icon| icon.into()),
nodes,
}
Expand All @@ -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 {
Expand All @@ -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::<Vec<String>>()
.join("\n\n"),
header = header,
title = title,
icon = icon,
)
}
Expand All @@ -61,7 +61,7 @@ impl Node for Highlight {
self.nodes.iter().map(|node| node.len()).sum::<usize>()
+ 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)
}
}
Expand All @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/nodes/yamd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ _I_
///
//
/ accordeon tab
/ accordion tab
\\
//
/ one more accordeon tab
/ one more accordion tab
\\
\\\
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f39ca8d

Please sign in to comment.