Add String to URL list helper with markdown parser

This commit is contained in:
Matthias Beyer 2015-12-05 16:55:20 +01:00
parent 7b14aafa9f
commit c35cd7ef15
3 changed files with 28 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#[macro_use] extern crate uuid;
#[macro_use] extern crate regex;
#[macro_use] extern crate prettytable;
extern crate pulldown_cmark;
extern crate url;
extern crate config;
extern crate open;

View 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>>()
}

View file

@ -5,6 +5,7 @@
pub mod cli;
pub mod header;
pub mod utils;
pub mod content;
/**
* Helpers for header specs
@ -40,3 +41,4 @@ pub mod spec {
}
}