add ability to distinguish links

This commit is contained in:
Gabriel 2025-07-22 15:22:43 -04:00
parent 6c0280febd
commit 0288aa9a2f
2 changed files with 38 additions and 22 deletions

View file

@ -48,6 +48,33 @@ fn process_children(children: &Vec<Item>) -> String {
result
}
fn has_image(children: &Vec<Item>) -> bool {
let mut result = false;
for c in children {
match c {
Item::Image(_) => {
return true;
}
_ => {}
}
}
result
}
fn has_video(children: &Vec<Item>) -> 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<Item>) -> Vec<Content> {
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;