From fd81de5d59d6ffcdc73ff9f8541d2262d1e15bc1 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Thu, 17 Sep 2020 08:08:03 -0700 Subject: [PATCH 1/2] add noopener to external links --- lib/markdown2.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index 58c1b707..b023fae5 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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) @@ -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 From 40050e71df2740e42e079855163c08bde196e266 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Thu, 17 Sep 2020 08:22:14 -0700 Subject: [PATCH 2/2] fix tests --- test/tm-cases/link_with_blank.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tm-cases/link_with_blank.html b/test/tm-cases/link_with_blank.html index 0d6e1dfe..df2c0037 100644 --- a/test/tm-cases/link_with_blank.html +++ b/test/tm-cases/link_with_blank.html @@ -1,5 +1,5 @@ -

Ref

+

Ref

Foo

-

One

+

One