add ability to distinguish links
This commit is contained in:
parent
6c0280febd
commit
0288aa9a2f
2 changed files with 38 additions and 22 deletions
58
src/lib.rs
58
src/lib.rs
|
@ -48,6 +48,33 @@ fn process_children(children: &Vec<Item>) -> String {
|
||||||
result
|
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 {
|
fn markdown_content(item: &Item) -> Content {
|
||||||
let mut markdown = String::new();
|
let mut markdown = String::new();
|
||||||
match item {
|
match item {
|
||||||
|
@ -99,9 +126,18 @@ fn process_content(items: Vec<Item>) -> Vec<Content> {
|
||||||
Item::Paragraph(_) => {
|
Item::Paragraph(_) => {
|
||||||
result.push(markdown_content(i));
|
result.push(markdown_content(i));
|
||||||
},
|
},
|
||||||
Item::Link(_,_) => {
|
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))
|
result.push(markdown_content(i))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Item::UnorderedList(_) => {
|
Item::UnorderedList(_) => {
|
||||||
result.push(markdown_content(i));
|
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)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
Loading…
Reference in a new issue