Add external link marker

This commit is contained in:
mDuo13
2019-02-07 13:37:30 -08:00
parent e0db009836
commit cc05858b1f
2 changed files with 36 additions and 0 deletions

View File

@@ -20,6 +20,10 @@ content_static_path: img
# PDF creation needs a dir for temporary files
temporary_files_path: /tmp/
# Custom filters live here and start with filter_
filter_paths:
- tool
default_filters:
- multicode_tabs
- standardize_header_ids
@@ -27,6 +31,7 @@ default_filters:
- callouts
- badges
- link_replacement
- external_links
callout_class: "devportal-callout"

View File

@@ -0,0 +1,31 @@
################################################
## External Link Marker
## Author: Rome Reginelli
## Copyright: Ripple Labs, 2019
##
## Finds external links and changes them to:
## - open in a new tab (target="_blank")
## - end with an "external link" icon
## (FontAwesome required)
################################################
import re
def filter_soup(soup, **kwargs):
"""
Adds an external link marker to external links
and makes them open in new tabs.
"""
extern_regex = re.compile(r"^https?://")
links = soup.find_all("a", href=True)
for link in links:
if extern_regex.match(link["href"]):
link["target"] = "_blank"
ex_link_marker = soup.new_tag("i", attrs={
"class":"fa fa-external-link",
"aria-hidden": "true"})
link.append(" ")
link.append(ex_link_marker)