html_to_pango: Switch to use the new library spawn from this.
Thanks to @danigm for spinning that part of fractal to a shared library.
This commit is contained in:
parent
af1cb43bd6
commit
a946ddfab1
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -698,6 +698,7 @@ dependencies = [
|
||||
name = "hammond-gtk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ammonia 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -709,6 +710,7 @@ dependencies = [
|
||||
"gtk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hammond-data 0.1.0",
|
||||
"hammond-downloader 0.1.0",
|
||||
"html2pango 0.1.0 (git+https://gitlab.gnome.org/danigm/html2pango)",
|
||||
"humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -738,6 +740,15 @@ dependencies = [
|
||||
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html2pango"
|
||||
version = "0.1.0"
|
||||
source = "git+https://gitlab.gnome.org/danigm/html2pango#5bf56226d889c6174473784d0fe437cab288b0d4"
|
||||
dependencies = [
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html5ever"
|
||||
version = "0.21.0"
|
||||
@ -2106,6 +2117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gtk 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "414f3522f550a0b4f65e089f00ffcd3987dab8b0be284cb979aa7f6a03d60516"
|
||||
"checksum gtk-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d9554cf5b3a85a13fb39258c65b04b262989c1d7a758f8f555b77a478621a91"
|
||||
"checksum handlebars 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7bdb08e879b8c78ee90f5022d121897c31ea022cb0cc6d13f2158c7a9fbabb1"
|
||||
"checksum html2pango 0.1.0 (git+https://gitlab.gnome.org/danigm/html2pango)" = "<none>"
|
||||
"checksum html5ever 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba3a1fd1857a714d410c191364c5d7bf8a6487c0ab5575146d37dd7eb17ef523"
|
||||
"checksum html5ever 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e579ac8647178ab915d400d7d22938bda5cd351c6c62e1c294d56884ccfc75fe"
|
||||
"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
|
||||
|
||||
@ -6,6 +6,7 @@ version = "0.1.0"
|
||||
workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
ammonia = "1.1.0"
|
||||
chrono = "0.4.1"
|
||||
dissolve = "0.2.2"
|
||||
gdk = "0.8.0"
|
||||
@ -25,6 +26,7 @@ take_mut = "0.2.2"
|
||||
regex = "0.2.10"
|
||||
reqwest = "0.8.5"
|
||||
serde_json = "1.0.13"
|
||||
html2pango = { git = "https://gitlab.gnome.org/danigm/html2pango" }
|
||||
|
||||
[dependencies.gtk]
|
||||
features = ["v3_22"]
|
||||
|
||||
@ -19,10 +19,12 @@ extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate ammonia;
|
||||
extern crate chrono;
|
||||
// extern crate dissolve;
|
||||
extern crate hammond_data;
|
||||
extern crate hammond_downloader;
|
||||
extern crate html2pango;
|
||||
extern crate humansize;
|
||||
extern crate loggerv;
|
||||
extern crate open;
|
||||
|
||||
@ -257,49 +257,6 @@ pub fn time_period_to_duration(time: i64, period: &str) -> Duration {
|
||||
}
|
||||
}
|
||||
|
||||
/// https://gitlab.gnome.org/World/fractal/blob/da016b252a0710ffd324469cd2059e3e090695eb/fractal-gtk/src/util.rs#L44-79
|
||||
/// Converts the input `&str` to pango format, replacing special characters
|
||||
/// `&, < and >` and parses URLS to show as a link
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let m = markup("this is parsed");
|
||||
/// assert_eq!(&m, "this is parsed");
|
||||
///
|
||||
/// let m = markup("this is <span>parsed</span>");
|
||||
/// assert_eq!(&m, "this is <parsed>");
|
||||
///
|
||||
/// let m = markup();
|
||||
/// assert_eq!(&m, "with links: <a href=\"http://gnome.org\">http://gnome.org</a> ");
|
||||
/// ```
|
||||
pub fn html_to_pango_markup(s: &str) -> String {
|
||||
let mut out = String::from(s);
|
||||
|
||||
out = String::from(out.trim());
|
||||
out = out.replace('&', "&");
|
||||
out = out.replace('<', "<");
|
||||
out = out.replace('>', ">");
|
||||
|
||||
let amp = "(&)";
|
||||
let domain = "[^\\s,)(\"]+";
|
||||
let param = format!("({amp}?\\w+(=[\\w._-]+)?)", amp = amp);
|
||||
let params = format!("(\\?{param}*)*", param = param);
|
||||
let hash = "(#[\\w._-]+)?";
|
||||
|
||||
let regex_str = format!(
|
||||
"(https?://{domain}{params}{hash})",
|
||||
domain = domain,
|
||||
params = params,
|
||||
hash = hash
|
||||
);
|
||||
|
||||
let re = Regex::new(®ex_str).unwrap();
|
||||
out = String::from(re.replace_all(&out, "<a href=\"$0\">$0</a>"));
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
// use dissolve;
|
||||
use failure::Error;
|
||||
// use glib;
|
||||
use ammonia;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use html2pango::markup as html_to_pango_markup;
|
||||
use open;
|
||||
|
||||
use hammond_data::Podcast;
|
||||
@ -10,7 +12,7 @@ use hammond_data::dbqueries;
|
||||
// use hammond_data::utils::replace_extra_spaces;
|
||||
|
||||
use app::Action;
|
||||
use utils::{html_to_pango_markup, set_image_from_path};
|
||||
use utils::set_image_from_path;
|
||||
// use utils::set_image_from_path;
|
||||
use widgets::episode::episodes_listbox;
|
||||
|
||||
@ -123,7 +125,8 @@ impl ShowWidget {
|
||||
// markup.
|
||||
// let desc = dissolve::strip_html_tags(text).join(" ");
|
||||
// self.description.set_text(&replace_extra_spaces(&desc));
|
||||
self.description.set_markup(&html_to_pango_markup(text));
|
||||
self.description
|
||||
.set_markup(&ammonia::clean(&html_to_pango_markup(text)));
|
||||
}
|
||||
|
||||
/// Set scrolled window vertical adjustment.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user