Skip to content
Permalink
Browse files

BUG: Fix wrapping non-raw URLs (e.g. in HTML)

  • Loading branch information...
kernc committed Apr 30, 2019
1 parent 43f28dd commit ca359aa69a20c9d10dddd716f9eb86e608159192
Showing with 5 additions and 1 deletion.
  1. +1 −1 pdoc/html_helpers.py
  2. +4 −0 pdoc/test/__init__.py
@@ -279,7 +279,7 @@ def doctests(text,
@staticmethod
def raw_urls(text):
"""Wrap URLs in Python-Markdown-compatible <angle brackets>."""
return re.sub(r'(?<!<)(\s*)((?:http|ftp)s?://[^>)\s]+)(\s*)(?!>)', r'\1<\2>\3', text)
return re.sub(r'(?<![<"\'])(\s*)((?:http|ftp)s?://[^>)\s]+)(\s*)', r'\1<\2>\3', text)


def to_html(text: str, docformat: str = 'numpy,google', *,
@@ -960,6 +960,8 @@ def test_reST_include(self):
def test_urls(self):
text = """Beautiful Soup
http://www.foo.bar
http://www.foo.bar?q="foo"
<a href="https://travis-ci.org/cs01/pygdbmi"><img src="https://foo" /></a>
<https://foo.bar>
Work [like this](http://foo/) and [like that].
@@ -969,6 +971,8 @@ def test_urls(self):
data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"""
expected = """<p>Beautiful Soup
<a href="http://www.foo.bar">http://www.foo.bar</a>
<a href="http://www.foo.bar?q=&quot;foo&quot;">http://www.foo.bar?q="foo"</a>
<a href="https://travis-ci.org/cs01/pygdbmi"><img src="https://foo" /></a>
<a href="https://foo.bar">https://foo.bar</a></p>
<p>Work <a href="http://foo/">like this</a> and <a href="ftp://bar">like that</a>.</p>
<p>data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D</p>"""

0 comments on commit ca359aa

Please sign in to comment.
You can’t perform that action at this time.