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