diff --git a/src/lib.rs b/src/lib.rs index 93ba7f5..b833869 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,33 @@ fn process_children(children: &Vec) -> String { result } +fn has_image(children: &Vec) -> bool { + let mut result = false; + for c in children { + match c { + Item::Image(_) => { + return true; + } + _ => {} + } + } + result +} + +fn has_video(children: &Vec) -> bool{ + let mut result = false; + for c in children { + match c { + Item::Video(_) => { + return true; + } + _ => {} + } + + } + false +} + fn markdown_content(item: &Item) -> Content { let mut markdown = String::new(); match item { @@ -99,8 +126,17 @@ fn process_content(items: Vec) -> Vec { Item::Paragraph(_) => { result.push(markdown_content(i)); }, - Item::Link(_,_) => { - result.push(markdown_content(i)) + Item::Link(_,children) => { + if has_video(children){ + result.push(Content::Markdown("Unsupported video".to_owned())); + } + else if has_image(children){ + result.push(Content::Markdown("Unsupported image".to_owned())); + + } + else { + result.push(markdown_content(i)) + } } Item::UnorderedList(_) => { result.push(markdown_content(i)); @@ -232,25 +268,5 @@ fn parse_items(n: ego_tree::NodeRef<'_,Node>) -> Item{ } -/* -Ideally I would verify what works and write tests for it. -I also need a function to process markdown items. -*/ -/* -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} - */ #[cfg(test)] mod tests; \ No newline at end of file diff --git a/src/tests.rs b/src/tests/mod.rs similarity index 100% rename from src/tests.rs rename to src/tests/mod.rs