Add String to URL list helper with markdown parser
This commit is contained in:
parent
7b14aafa9f
commit
c35cd7ef15
3 changed files with 28 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
#[macro_use] extern crate uuid;
|
#[macro_use] extern crate uuid;
|
||||||
#[macro_use] extern crate regex;
|
#[macro_use] extern crate regex;
|
||||||
#[macro_use] extern crate prettytable;
|
#[macro_use] extern crate prettytable;
|
||||||
|
extern crate pulldown_cmark;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate config;
|
extern crate config;
|
||||||
extern crate open;
|
extern crate open;
|
||||||
|
|
25
src/module/helpers/content.rs
Normal file
25
src/module/helpers/content.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
pub fn extract_links(s: &String) -> Vec<String> {
|
||||||
|
use pulldown_cmark::Parser;
|
||||||
|
use pulldown_cmark::Event;
|
||||||
|
use pulldown_cmark::Tag;
|
||||||
|
|
||||||
|
Parser::new(&s[..])
|
||||||
|
.filter_map(|e| {
|
||||||
|
match e {
|
||||||
|
Event::Start(t) => Some(t),
|
||||||
|
Event::End(t) => Some(t),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter_map(|tag| {
|
||||||
|
match tag {
|
||||||
|
Tag::Link(url, text) => Some((url, text)),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|(url, text)| {
|
||||||
|
text.into_owned()
|
||||||
|
}).collect::<Vec<String>>()
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
pub mod content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers for header specs
|
* Helpers for header specs
|
||||||
|
@ -40,3 +41,4 @@ pub mod spec {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue