From c35cd7ef1580ea744a42480cff97e04cbd3771e5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 5 Dec 2015 16:55:20 +0100 Subject: [PATCH] Add String to URL list helper with markdown parser --- src/main.rs | 1 + src/module/helpers/content.rs | 25 +++++++++++++++++++++++++ src/module/helpers/mod.rs | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 src/module/helpers/content.rs diff --git a/src/main.rs b/src/main.rs index 37ef4914..5dff5484 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/module/helpers/content.rs b/src/module/helpers/content.rs new file mode 100644 index 00000000..64054e37 --- /dev/null +++ b/src/module/helpers/content.rs @@ -0,0 +1,25 @@ + +pub fn extract_links(s: &String) -> Vec { + 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::>() +} + diff --git a/src/module/helpers/mod.rs b/src/module/helpers/mod.rs index b836be85..81c63dbb 100644 --- a/src/module/helpers/mod.rs +++ b/src/module/helpers/mod.rs @@ -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 { } } +