diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index a59c1ef..810cbbb 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -15,6 +15,7 @@ log = "0.3.8" loggerv = "0.6.0" open = "1.2.1" rayon = "0.9.0" +regex = "0.2.3" [dependencies.diesel] features = ["sqlite"] diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 5afcb5f..d231464 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -12,6 +12,7 @@ extern crate hammond_downloader; extern crate log; extern crate loggerv; extern crate open; +extern crate regex; // extern crate rayon; // use rayon::prelude::*; diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 14e8b46..5402b90 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -9,8 +9,10 @@ use hammond_downloader::downloader; use std::{thread, time}; use std::cell::RefCell; use std::sync::mpsc::{channel, Receiver}; +use std::borrow::Cow; use content; +use regex::Regex; type Foo = RefCell)>>; @@ -69,6 +71,18 @@ pub fn get_pixbuf_from_path(pd: &Podcast) -> Option { Pixbuf::new_from_file_at_scale(&img_path, 256, 256, true).ok() } +#[allow(dead_code)] +// WIP: parse html to markup +pub fn html_to_markup(s: &mut str) -> Cow { + s.trim(); + s.replace('&', "&"); + s.replace('<', "<"); + s.replace('>', ">"); + + let re = Regex::new("(?Phttps?://[^\\s&,)(\"]+(&\\w=[\\w._-]?)*(#[\\w._-]+)?)").unwrap(); + re.replace_all(s, "$url") +} + #[cfg(test)] mod tests { use hammond_data::Source;