mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Add external link marker
This commit is contained in:
@@ -20,6 +20,10 @@ content_static_path: img
|
|||||||
# PDF creation needs a dir for temporary files
|
# PDF creation needs a dir for temporary files
|
||||||
temporary_files_path: /tmp/
|
temporary_files_path: /tmp/
|
||||||
|
|
||||||
|
# Custom filters live here and start with filter_
|
||||||
|
filter_paths:
|
||||||
|
- tool
|
||||||
|
|
||||||
default_filters:
|
default_filters:
|
||||||
- multicode_tabs
|
- multicode_tabs
|
||||||
- standardize_header_ids
|
- standardize_header_ids
|
||||||
@@ -27,6 +31,7 @@ default_filters:
|
|||||||
- callouts
|
- callouts
|
||||||
- badges
|
- badges
|
||||||
- link_replacement
|
- link_replacement
|
||||||
|
- external_links
|
||||||
|
|
||||||
callout_class: "devportal-callout"
|
callout_class: "devportal-callout"
|
||||||
|
|
||||||
|
|||||||
31
tool/filter_external_links.py
Normal file
31
tool/filter_external_links.py
Normal 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)
|
||||||
Reference in New Issue
Block a user