From 4d4b52075e906f77b49a25f7690c936ad5311992 Mon Sep 17 00:00:00 2001
From: Alejandro Alonso
Date: Fri, 13 Mar 2015 13:03:40 +0100
Subject: [PATCH] Bug 2444 links in rich content editor
---
taiga/mdrender/extensions/autolink.py | 1 -
taiga/mdrender/extensions/target_link.py | 46 ++++++++++++++++++++++++
taiga/mdrender/service.py | 5 +--
tests/unit/test_mdrender.py | 8 ++---
4 files changed, 53 insertions(+), 7 deletions(-)
create mode 100644 taiga/mdrender/extensions/target_link.py
diff --git a/taiga/mdrender/extensions/autolink.py b/taiga/mdrender/extensions/autolink.py
index 7676bd18..4413353a 100644
--- a/taiga/mdrender/extensions/autolink.py
+++ b/taiga/mdrender/extensions/autolink.py
@@ -36,7 +36,6 @@ class AutolinkExtension(markdown.Extension):
* GitHub only accepts URLs with protocols or "www.", whereas Gruber's regex
accepts things like "foo.com/bar".
"""
-
def extendMarkdown(self, md, md_globals):
url_re = r'(?i)\b((?:(?:ftp|https?)://|www\d{0,3}[.])([^\s<>]+))'
autolink = AutolinkPattern(url_re, md)
diff --git a/taiga/mdrender/extensions/target_link.py b/taiga/mdrender/extensions/target_link.py
new file mode 100644
index 00000000..26cc6a5f
--- /dev/null
+++ b/taiga/mdrender/extensions/target_link.py
@@ -0,0 +1,46 @@
+# Copyright (C) 2015 Andrey Antukh
+# Copyright (C) 2015 Jesús Espino
+# Copyright (C) 2015 David Barragán
+# Copyright (C) 2015 Alejandro Alonso
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+
+import re
+import markdown
+
+from markdown.treeprocessors import Treeprocessor
+
+from taiga.front import resolve
+
+
+class TargetBlankLinkExtension(markdown.Extension):
+ """An extension that add target="_blank" to all external links."""
+ def extendMarkdown(self, md, md_globals):
+ md.treeprocessors.add("target_blank_links",
+ TargetBlankLinksTreeprocessor(md),
+ "example of reference link
"
+ expected_result = "An example of reference link
"
source = "An [example][id] of reference link\n [id]: http://example.com/ \"Title\""
assert render(dummy_project, source) == expected_result
def test_render_url_autolinks():
- expected_result = "Test the http://example.com/ autolink
"
+ expected_result = "Test the http://example.com/ autolink
"
source = "Test the http://example.com/ autolink"
assert render(dummy_project, source) == expected_result
def test_render_url_autolinks_without_http():
- expected_result = "Test the www.example.com autolink
"
+ expected_result = "Test the www.example.com autolink
"
source = "Test the www.example.com autolink"
assert render(dummy_project, source) == expected_result
def test_render_url_automail():
- expected_result = "Test the example@example.com automail
"
+ expected_result = "Test the example@example.com automail
"
source = "Test the example@example.com automail"
assert render(dummy_project, source) == expected_result