WIP markup to html parser func.

This commit is contained in:
Jordan Petridis 2017-12-07 06:41:10 +02:00
parent c07d240532
commit d7af108833
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 16 additions and 0 deletions

View File

@ -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"]

View File

@ -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::*;

View File

@ -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<Option<(gtk::Stack, Receiver<bool>)>>;
@ -69,6 +71,18 @@ pub fn get_pixbuf_from_path(pd: &Podcast) -> Option<Pixbuf> {
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<str> {
s.trim();
s.replace('&', "&amp;");
s.replace('<', "&lt;");
s.replace('>', "&gt;");
let re = Regex::new("(?P<url>https?://[^\\s&,)(\"]+(&\\w=[\\w._-]?)*(#[\\w._-]+)?)").unwrap();
re.replace_all(s, "<a href=\"$url\">$url</a>")
}
#[cfg(test)]
mod tests {
use hammond_data::Source;