Skip to content

Commit

Permalink
Remove cloudinary (#37)
Browse files Browse the repository at this point in the history
remove cloudinary galley node in favor of embed node
  • Loading branch information
Lurk authored Oct 31, 2023
1 parent 23e3f64 commit 764a886
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 147 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yamd"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Yet Another Markdown Document (flavor)"
Expand All @@ -12,5 +12,5 @@ keywords = ["markdown", "parser"]
pretty_assertions = "1.4.0"

[dependencies]
serde = { version = "1.0.188", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
chrono = { version = "0.4.31", features = ["serde"] }
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@
//! ![alt text](url)
//! !!!
//! ```
//! ### CloudinaryImageGallery
//!
//! Element that allows to embed image gallery from cloudinary.com by providing username and tag.
//!
//! Example:
//! ```text
//! !!!
//! ! username
//! ! tag
//! !!!
//! ```
//!
//! ### Highlight
//!
Expand Down
27 changes: 6 additions & 21 deletions src/nodes/accordion_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use crate::toolkit::{
};

use super::{
accordion::Accordion, cloudinary_image_gallery::CloudinaryImageGallery, code::Code,
divider::Divider, embed::Embed, heading::Heading, image::Image, image_gallery::ImageGallery,
list::List, paragraph::Paragraph,
accordion::Accordion, code::Code, divider::Divider, embed::Embed, heading::Heading,
image::Image, image_gallery::ImageGallery, list::List, paragraph::Paragraph,
};

#[derive(Debug, PartialEq, Serialize, Clone)]
Expand All @@ -22,7 +21,6 @@ pub enum AccordionTabNodes {
Heading(Heading),
Image(Image),
ImageGallery(ImageGallery),
CloudinaryImageGallery(CloudinaryImageGallery),
List(List),
Embed(Embed),
Accordion(Accordion),
Expand All @@ -37,7 +35,6 @@ impl Display for AccordionTabNodes {
AccordionTabNodes::Heading(node) => write!(f, "{}", node),
AccordionTabNodes::Image(node) => write!(f, "{}", node),
AccordionTabNodes::ImageGallery(node) => write!(f, "{}", node),
AccordionTabNodes::CloudinaryImageGallery(node) => write!(f, "{}", node),
AccordionTabNodes::List(node) => write!(f, "{}", node),
AccordionTabNodes::Embed(node) => write!(f, "{}", node),
AccordionTabNodes::Accordion(node) => write!(f, "{}", node),
Expand All @@ -54,7 +51,6 @@ impl Node for AccordionTabNodes {
AccordionTabNodes::Heading(node) => node.len(),
AccordionTabNodes::Image(node) => node.len(),
AccordionTabNodes::ImageGallery(node) => node.len(),
AccordionTabNodes::CloudinaryImageGallery(node) => node.len(),
AccordionTabNodes::List(node) => node.len(),
AccordionTabNodes::Embed(node) => node.len(),
AccordionTabNodes::Accordion(node) => node.len(),
Expand Down Expand Up @@ -88,12 +84,6 @@ impl From<ImageGallery> for AccordionTabNodes {
}
}

impl From<CloudinaryImageGallery> for AccordionTabNodes {
fn from(value: CloudinaryImageGallery) -> Self {
Self::CloudinaryImageGallery(value)
}
}

impl From<List> for AccordionTabNodes {
fn from(value: List) -> Self {
Self::List(value)
Expand Down Expand Up @@ -185,7 +175,6 @@ impl Branch<AccordionTabNodes> for AccordionTab {
Heading::maybe_node(),
Image::maybe_node(),
ImageGallery::maybe_node(),
CloudinaryImageGallery::maybe_node(),
List::maybe_node(),
Embed::maybe_node(),
Accordion::maybe_node(),
Expand Down Expand Up @@ -229,9 +218,8 @@ mod cfg {

use crate::{
nodes::{
accordion_tab::AccordionTab, bold::Bold,
cloudinary_image_gallery::CloudinaryImageGallery, code::Code, divider::Divider,
embed::Embed, heading::Heading, image::Image, image_gallery::ImageGallery, list::List,
accordion_tab::AccordionTab, bold::Bold, code::Code, divider::Divider, embed::Embed,
heading::Heading, image::Image, image_gallery::ImageGallery, list::List,
list::ListTypes::*, list_item::ListItem, list_item_content::ListItemContent,
paragraph::Paragraph, text::Text,
},
Expand Down Expand Up @@ -345,10 +333,7 @@ t**b**
{{youtube|123}}
!!!!
! username
! tag
!!!!
{{cloudinary_gallery|cloud_name&tag}}
\\"#;
let tab = AccordionTab::new_with_nodes(
true,
Expand Down Expand Up @@ -401,7 +386,7 @@ t**b**
)
.into(),
Embed::new("youtube", "123", false).into(),
CloudinaryImageGallery::new("username", "tag", true).into(),
Embed::new("cloudinary_gallery", "cloud_name&tag", true).into(),
],
);
assert_eq!(tab.to_string(), input);
Expand Down
84 changes: 0 additions & 84 deletions src/nodes/cloudinary_image_gallery.rs

This file was deleted.

16 changes: 8 additions & 8 deletions src/nodes/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use crate::toolkit::{deserializer::Deserializer, matcher::Matcher, node::Node};

#[derive(Debug, PartialEq, Serialize, Clone)]
pub struct Embed {
pub url: String,
pub args: String,
pub kind: String,
#[serde(skip_serializing)]
consumed_all_input: bool,
pub consumed_all_input: bool,
}

impl Embed {
pub fn new<S: Into<String>>(kind: S, url: S, consumed_all_input: bool) -> Self {
pub fn new<S: Into<String>>(kind: S, args: S, consumed_all_input: bool) -> Self {
Self {
kind: kind.into(),
url: url.into(),
args: args.into(),
consumed_all_input,
}
}
Expand All @@ -25,14 +25,14 @@ impl Embed {
impl Display for Embed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let end = if self.consumed_all_input { "" } else { "\n\n" };
write!(f, "{{{{{}|{}}}}}{}", self.kind, self.url, end)
write!(f, "{{{{{}|{}}}}}{}", self.kind, self.args, end)
}
}

impl Node for Embed {
fn len(&self) -> usize {
let end = if self.consumed_all_input { 0 } else { 2 };
5 + self.kind.len() + self.url.len() + end
5 + self.kind.len() + self.args.len() + end
}
}

Expand All @@ -44,11 +44,11 @@ impl Deserializer for Embed {
let mut matcher = Matcher::new(input);
if let Some(embed) = matcher.get_match("{{", "}}", false) {
let mut embed = embed.body.split('|');
if let (Some(kind), Some(url)) = (embed.next(), embed.next()) {
if let (Some(kind), Some(args)) = (embed.next(), embed.next()) {
let consumed_all_input = matcher.get_match("\n\n", "", false).is_none();
return Some(Self::new(
kind.to_string(),
url.to_string(),
args.to_string(),
consumed_all_input,
));
}
Expand Down
1 change: 0 additions & 1 deletion src/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod accordion;
pub mod accordion_tab;
pub mod anchor;
pub mod bold;
pub mod cloudinary_image_gallery;
pub mod code;
pub mod divider;
pub mod embed;
Expand Down
25 changes: 5 additions & 20 deletions src/nodes/yamd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use crate::{
};

use super::{
accordion::Accordion, cloudinary_image_gallery::CloudinaryImageGallery, code::Code,
divider::Divider, embed::Embed, highlight::Highlight, image::Image,
image_gallery::ImageGallery, list::List, metadata::Metadata,
accordion::Accordion, code::Code, divider::Divider, embed::Embed, highlight::Highlight,
image::Image, image_gallery::ImageGallery, list::List, metadata::Metadata,
};

#[derive(Debug, PartialEq, Serialize, Clone)]
Expand All @@ -27,7 +26,6 @@ pub enum YamdNodes {
Highlight(Highlight),
Divider(Divider),
Embed(Embed),
CloudinaryImageGallery(CloudinaryImageGallery),
Accordion(Accordion),
}

Expand Down Expand Up @@ -85,12 +83,6 @@ impl From<Embed> for YamdNodes {
}
}

impl From<CloudinaryImageGallery> for YamdNodes {
fn from(value: CloudinaryImageGallery) -> Self {
YamdNodes::CloudinaryImageGallery(value)
}
}

impl From<Accordion> for YamdNodes {
fn from(value: Accordion) -> Self {
YamdNodes::Accordion(value)
Expand All @@ -109,7 +101,6 @@ impl Display for YamdNodes {
YamdNodes::Highlight(node) => write!(f, "{}", node),
YamdNodes::Divider(node) => write!(f, "{}", node),
YamdNodes::Embed(node) => write!(f, "{}", node),
YamdNodes::CloudinaryImageGallery(node) => write!(f, "{}", node),
YamdNodes::Accordion(node) => write!(f, "{}", node),
}
}
Expand All @@ -127,7 +118,6 @@ impl Node for YamdNodes {
YamdNodes::Highlight(node) => node.len(),
YamdNodes::Divider(node) => node.len(),
YamdNodes::Embed(node) => node.len(),
YamdNodes::CloudinaryImageGallery(node) => node.len(),
YamdNodes::Accordion(node) => node.len(),
}
}
Expand Down Expand Up @@ -168,7 +158,6 @@ impl Branch<YamdNodes> for Yamd {
Highlight::maybe_node(),
Divider::maybe_node(),
Embed::maybe_node(),
CloudinaryImageGallery::maybe_node(),
Accordion::maybe_node(),
]
}
Expand Down Expand Up @@ -221,7 +210,6 @@ mod tests {
accordion::Accordion,
accordion_tab::AccordionTab,
bold::Bold,
cloudinary_image_gallery::CloudinaryImageGallery,
code::Code,
divider::Divider,
embed::Embed,
Expand Down Expand Up @@ -278,10 +266,7 @@ _I_
{{youtube|123}}
!!!!
! username
! tag
!!!!
{{cloudinary_gallery|cloud_name&tag}}
///
//
Expand Down Expand Up @@ -399,7 +384,7 @@ end"#;
)
.into(),
Embed::new("youtube", "123", false).into(),
CloudinaryImageGallery::new("username", "tag", false).into(),
Embed::new("cloudinary_gallery", "cloud_name&tag", false).into(),
Accordion::new_with_nodes(
false,
vec![
Expand Down Expand Up @@ -492,7 +477,7 @@ end"#;
)
.into(),
Embed::new("youtube", "123", false).into(),
CloudinaryImageGallery::new("username", "tag", false).into(),
Embed::new("cloudinary_gallery", "cloud_name&tag", false).into(),
Accordion::new_with_nodes(
false,
vec![
Expand Down

0 comments on commit 764a886

Please sign in to comment.