From 21ecf52f0aa8085cbbdb340966fcfab1b8dc8dd6 Mon Sep 17 00:00:00 2001 From: teury Date: Wed, 2 Jan 2019 15:10:43 -0400 Subject: [PATCH] link rel no follow, target --- src/wiki/conf/settings.py | 3 ++- src/wiki/plugins/links/mdx/urlize.py | 4 ++-- tests/plugins/links/test_urlize.py | 13 +++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/wiki/conf/settings.py b/src/wiki/conf/settings.py index 6570429f..a677ec46 100644 --- a/src/wiki/conf/settings.py +++ b/src/wiki/conf/settings.py @@ -102,7 +102,8 @@ for tag in MARKDOWN_HTML_WHITELIST: if tag not in _default_attribute_whitelist: _default_attribute_whitelist[tag] = [] _default_attribute_whitelist[tag].append('class') - _default_attribute_whitelist[tag].append('id') + _default_attribute_whitelist[tag].append('target') + _default_attribute_whitelist[tag].append('rel') _default_attribute_whitelist['img'].append('src') _default_attribute_whitelist['img'].append('alt') diff --git a/src/wiki/plugins/links/mdx/urlize.py b/src/wiki/plugins/links/mdx/urlize.py index 800a3514..8825f439 100644 --- a/src/wiki/plugins/links/mdx/urlize.py +++ b/src/wiki/plugins/links/mdx/urlize.py @@ -78,8 +78,7 @@ URLIZE_RE = ( r'([A-F0-9]{1,4}:){1,6}:([A-F0-9]{1,4}){1,6}|' # IPv6, zeros in middle removed. r'\[?([A-F0-9]{1,4}:){1,6}:\]?|' # IPv6, trailing zeros removed r'\[?::\]?|' # IPv6, just "empty" address - r'([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+([A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # FQDN - r'localhost' # localhost + r'([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+([A-Z]{2,6}\.?|[A-Z]{2,}\.?)' # FQDN r')' # end host identifier group # Optional port @@ -156,6 +155,7 @@ class UrlizePattern(markdown.inlinepatterns.Pattern): el = markdown.util.etree.Element("a") el.set('href', url) el.set('target', '_blank') + el.set('rel', 'nofollow') el.append(icon) el.append(span_text) diff --git a/tests/plugins/links/test_urlize.py b/tests/plugins/links/test_urlize.py index 2da929b8..6bf2be9a 100644 --- a/tests/plugins/links/test_urlize.py +++ b/tests/plugins/links/test_urlize.py @@ -7,7 +7,7 @@ from wiki.plugins.links.mdx.urlize import UrlizeExtension, makeExtension # Template accepts two strings - href value and link text value. EXPECTED_LINK_TEMPLATE = ( - '' + '' '' '' '' @@ -104,14 +104,11 @@ FIXTURE_POSITIVE_MATCHES = [ ), ( 'localhost', - EXPECTED_PARAGRAPH_TEMPLATE % ('http://localhost', 'localhost') + '

localhosts

', ), # Test port section. - ( - 'localhost:8000', - EXPECTED_PARAGRAPH_TEMPLATE % ('http://localhost:8000', 'localhost:8000') - ), + ( '10.1.1.1:8000', EXPECTED_PARAGRAPH_TEMPLATE % ('http://10.1.1.1:8000', '10.1.1.1:8000') @@ -165,7 +162,7 @@ FIXTURE_NEGATIVE_MATCHES = [ # localhost as part of another word. ( 'localhosts', - '

localhosts

' + EXPECTED_PARAGRAPH_TEMPLATE % ('http://localhost', 'localhost') ), # Invalid FQDNs. @@ -251,4 +248,4 @@ class TestUrlizeExtension: def test_makeExtension_return_value(): extension = makeExtension() - assert isinstance(extension, UrlizeExtension) + assert isinstance(extension, UrlizeExtension) \ No newline at end of file -- 2.45.2