Skip to content

Commit

Permalink
add noopener to external links
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Sep 18, 2020
1 parent 175fe99 commit fd81de5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/markdown2.py
Expand Up @@ -389,12 +389,17 @@ def convert(self, text):
# return the removed text warning to its markdown.py compatible form
text = text.replace(self.html_removed_text, self.html_removed_text_compat)

if "nofollow" in self.extras:
text = self._a_nofollow.sub(r'<\1 rel="nofollow"\2', text)

if "target-blank-links" in self.extras:
text = self._a_blank.sub(r'<\1 target="_blank"\2', text)

if "nofollow" in self.extras:
if "target-blank-links" in self.extras:
text = self._a_nofollow.sub(r'<\1 rel="nofollow noopener"\2', text)
else:
text = self._a_nofollow.sub(r'<\1 rel="nofollow"\2', text)
elif "target-blank-links" in self.extras:
text = self._a_nofollow.sub(r'<\1 rel="noopener"\2', text)

if "toc" in self.extras and self._toc:
self._toc_html = calculate_toc_html(self._toc)

Expand Down Expand Up @@ -2234,7 +2239,7 @@ def _encode_amps_and_angles(self, text):
def _encode_incomplete_tags(self, text):
if self.safe_mode not in ("replace", "escape"):
return text

if text.endswith(">"):
return text # this is not an incomplete tag, this is a link in the form <http://x.y.z>

Expand Down

0 comments on commit fd81de5

Please sign in to comment.