From dcf5ca3e0ac20cd6fae2f951652ba040d8974203 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 13 Feb 2021 16:36:13 -0600 Subject: [PATCH] Add target="blank" on urls --- content/src/lib.rs | 2 ++ content/src/render.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/content/src/lib.rs b/content/src/lib.rs index cea2471..b1d7f15 100644 --- a/content/src/lib.rs +++ b/content/src/lib.rs @@ -52,6 +52,7 @@ fn attribute_filter<'u>(element: &str, attribute: &str, value: &'u str) -> Optio | ("span", "data-symbol") | ("blockquote", "data-author") | ("a", "rel") + | ("a", "target") | ("a", "title") | ("a", "href") | ("a", "class") @@ -121,6 +122,7 @@ static AMMONIA_CONFIG: Lazy = Lazy::new(|| { .url_schemes(schemes) .link_rel(Some("nofollow noopener noreferer")) .attribute_filter(attribute_filter) + .add_tag_attributes("a", &["target"]) .add_tag_attributes("span", &["style"]) .add_tag_attributes("div", &["style"]); diff --git a/content/src/render.rs b/content/src/render.rs index 143b176..ebd1565 100644 --- a/content/src/render.rs +++ b/content/src/render.rs @@ -211,7 +211,7 @@ fn render_nodes(nodes: Vec) -> String { Tag::Br => String::from("
"), Tag::Url if !children.is_empty() => { if let Some(href) = attr { - format!("", href) + format!("", href) + &render_nodes(children) + "" } else { @@ -221,7 +221,7 @@ fn render_nodes(nodes: Vec) -> String { _ => String::new(), }, RenderNode::Url { href } => format!( - "{href}", + "{href}", href = href ), RenderNode::IconText {