From 6a4170b4c81832fc0c6a018340478ca73b975842 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 11 Jul 2025 10:00:21 -0400 Subject: [PATCH] Figured out how to make using the enum a lot less annoying! --- src/elements.rs | 46 ---------------------------------------------- src/lib.rs | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 59 deletions(-) delete mode 100644 src/elements.rs diff --git a/src/elements.rs b/src/elements.rs deleted file mode 100644 index 722416a..0000000 --- a/src/elements.rs +++ /dev/null @@ -1,46 +0,0 @@ - -#[derive(Debug)] -pub enum Item { - Ignore, - Text(String), - //text, links, formatting are all markdown - //arguably, for better control it will be best to turn markdown into its own set of items - Image(String), - Gif(String), //can't detect gif from image, has to be handled on front-end - Svg(String),// wont' support for a while I think. - Video(Video), - Audio(Audio), - Source(String), - BoldedText(Vec), - EmphasisText(Vec), - UnorderedList(Vec), - OrderedList(Vec), - ListItem(Vec), - Paragraph(Vec),//gotta replace this with specific items, needlessly flexible - Link(Link), -} - -#[derive(Debug)] -pub struct Link{ - pub href: String, - pub children: Vec -} - -#[derive(Debug)] -pub struct Video{ - pub children: Vec - //might have to do fancy things to detect autoplay... -} -#[derive(Debug)] -pub struct Audio{ - pub children: Vec - //might have to do fancy things to detect autoplay... -} -#[derive(Debug)] -pub enum ContainerTag{ - P, - Div, - Button,//arguably redundant - Table, - -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d4ca31f..c3f97e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,33 @@ use scraper::{ElementRef, Html, Node}; -pub mod elements; -use elements::*; /* The goal here is to flatten the DOM as much as possible. paragraphs with fancy formatting are turned into markdown, same with */ + + +#[derive(Debug)] +pub enum Item { + Ignore, + Text(String), + //text, links, formatting are all markdown + //arguably, for better control it will be best to turn markdown into its own set of items + Image(String), + Gif(String), //can't detect gif from image, has to be handled on front-end + Svg(String),// wont' support for a while I think. + Video(Vec), + Audio(Vec), + Source(String), + BoldedText(Vec), + EmphasisText(Vec), + UnorderedList(Vec), + OrderedList(Vec), + ListItem(Vec), + Paragraph(Vec),//gotta replace this with specific items, needlessly flexible + Link(String,Vec), +} + + pub fn itemize_content(content: &str) -> Vec { let frag = Html::parse_fragment(content); frag.root_element().children().map(|e|{ @@ -37,12 +59,9 @@ fn parse_items(n: ego_tree::NodeRef<'_,Node>) -> Item{ Some(link) => {link} None => {""} }; - return Item::Link( - Link{ - href: href.to_owned(), - children: get_children(&el) - } - ) + return Item::Link(href.to_owned(),get_children(&el)) + + } "img" => { match el.attr("src") { @@ -61,11 +80,7 @@ fn parse_items(n: ego_tree::NodeRef<'_,Node>) -> Item{ } } "video" => { - return Item::Video( - Video{ - children: get_children(&el) - } - ) + return Item::Video(get_children(&el)) } "ol" => { return Item::OrderedList(get_children(&el))