lazy search for media source
This commit is contained in:
parent
0288aa9a2f
commit
3432fec624
1 changed files with 37 additions and 1 deletions
38
src/lib.rs
38
src/lib.rs
|
@ -22,6 +22,7 @@ pub fn parse_content(c: &str) -> Vec<Content>{
|
||||||
match i {
|
match i {
|
||||||
Content::Markdown(s) => {
|
Content::Markdown(s) => {
|
||||||
Content::MarkdownParsed(markdown::parse(&s).collect())
|
Content::MarkdownParsed(markdown::parse(&s).collect())
|
||||||
|
//this is super lazy but it works....
|
||||||
}
|
}
|
||||||
_ => {i}
|
_ => {i}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +111,42 @@ fn markdown_content(item: &Item) -> Content {
|
||||||
Content::Markdown(markdown)
|
Content::Markdown(markdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn media_content(_: &Item) -> Content{
|
fn get_media_source(children: &Vec<Item>) -> Option<String> {
|
||||||
|
for c in children {
|
||||||
|
match c {
|
||||||
|
Item::Source(src) => {
|
||||||
|
return Some(src.to_owned());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn media_content(item: &Item) -> Content{
|
||||||
|
match item {
|
||||||
|
Item::Audio(children) => {
|
||||||
|
match get_media_source(children) {
|
||||||
|
Some(s) => {
|
||||||
|
return Content::Audio(s);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return Content::Markdown("<Audio Element with no source>".to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Item::Video(children) => {
|
||||||
|
match get_media_source(children) {
|
||||||
|
Some(source) => {
|
||||||
|
return Content::Video(source)
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return Content::Markdown("<Video element with no source>".to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
Content::Markdown("Media not supported yet".to_owned())
|
Content::Markdown("Media not supported yet".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue