Add target="blank" on urls
This commit is contained in:
parent
c723bb759a
commit
dcf5ca3e0a
|
@ -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<Builder> = 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"]);
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ fn render_nodes(nodes: Vec<RenderNode>) -> String {
|
|||
Tag::Br => String::from("<br>"),
|
||||
Tag::Url if !children.is_empty() => {
|
||||
if let Some(href) = attr {
|
||||
format!("<a href=\"{}\" rel=\"noopener noreferer nofollow\">", href)
|
||||
format!("<a href=\"{}\" target=\"_blank\" rel=\"noopener noreferer nofollow\">", href)
|
||||
+ &render_nodes(children)
|
||||
+ "</a>"
|
||||
} else {
|
||||
|
@ -221,7 +221,7 @@ fn render_nodes(nodes: Vec<RenderNode>) -> String {
|
|||
_ => String::new(),
|
||||
},
|
||||
RenderNode::Url { href } => format!(
|
||||
"<a href=\"{href}\" rel=\"noopener noreferer nofollow\">{href}</a>",
|
||||
"<a href=\"{href}\" target=\"blank\" rel=\"noopener noreferer nofollow\">{href}</a>",
|
||||
href = href
|
||||
),
|
||||
RenderNode::IconText {
|
||||
|
|
Loading…
Reference in a new issue