Support up to one level deep of nested parens in urls

(imported from commit 3f314b16a47b5267ddb0d18aa6c5456656895f77)
This commit is contained in:
Leo Franchi 2013-03-29 14:45:22 -04:00 committed by Keegan McAllister
parent 191231ab3d
commit d127d6f19f
2 changed files with 13 additions and 3 deletions

View File

@ -414,7 +414,10 @@ class Bugdown(markdown.Extension):
# #
# This rule must come after the built-in 'link' markdown linkifier to # This rule must come after the built-in 'link' markdown linkifier to
# avoid errors. # avoid errors.
http_link_regex = r'\b(?P<url>https?://[^\s]+?)(?=[^\w/]*(\s|\Z))' #
# We support up to 1 nested pair of paranthesis in a url
http_link_regex = r'\b(?P<url>https?://(?:(?:[^\s]+\([^\s)]+?\)[^\s]*?)|[^\s]+?))(?=[^\w/]*(\s|\Z))'
md.inlinePatterns.add('http_autolink', HttpLink(http_link_regex), '>link') md.inlinePatterns.add('http_autolink', HttpLink(http_link_regex), '>link')
# A link starts at a word boundary, and ends at space, punctuation, or end-of-input. # A link starts at a word boundary, and ends at space, punctuation, or end-of-input.

View File

@ -1999,6 +1999,12 @@ int x = 3
('http://j.mp/14Hwm3X', "<p>%s</p>", 'http://j.mp/14Hwm3X'), ('http://j.mp/14Hwm3X', "<p>%s</p>", 'http://j.mp/14Hwm3X'),
('http://localhost:9991/?show_debug=1', "<p>%s</p>", 'http://localhost:9991/?show_debug=1'), ('http://localhost:9991/?show_debug=1', "<p>%s</p>", 'http://localhost:9991/?show_debug=1'),
('anyone before? (http://d.pr/i/FMXO)', "<p>anyone before? (%s)</p>", 'http://d.pr/i/FMXO'), ('anyone before? (http://d.pr/i/FMXO)', "<p>anyone before? (%s)</p>", 'http://d.pr/i/FMXO'),
('(http://en.wikipedia.org/wiki/Each-way_(bet))',
'<p>(%s)</p>', 'http://en.wikipedia.org/wiki/Each-way_(bet)'),
('(http://en.wikipedia.org/wiki/Each-way_(bet)_(more_parens))',
'<p>(%s)</p>', 'http://en.wikipedia.org/wiki/Each-way_(bet)_(more_parens)'),
('http://en.wikipedia.org/wiki/Qt_(framework)', '<p>%s</p>', 'http://en.wikipedia.org/wiki/Qt_(framework)'),
('http://fr.wikipedia.org/wiki/Fichier:SMirC-facepalm.svg', ('http://fr.wikipedia.org/wiki/Fichier:SMirC-facepalm.svg',
'<p>%s</p>', 'http://fr.wikipedia.org/wiki/Fichier:SMirC-facepalm.svg'), '<p>%s</p>', 'http://fr.wikipedia.org/wiki/Fichier:SMirC-facepalm.svg'),
# Changed to .mov from .png to avoid inline preview # Changed to .mov from .png to avoid inline preview
@ -2068,8 +2074,9 @@ NY-Haskell/events/108707682/?a=co1.1_grp&amp;rv=co1.1\">Haskell NYC Meetup</a></
('[link](http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html)', ('[link](http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html)',
'<p><a href="http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html" target="_blank" title=\ '<p><a href="http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html" target="_blank" title=\
"http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html">link</a></p>'), "http://htmlpreview.github.com/?https://github.com/becdot/jsset/index.html">link</a></p>'),
# ('[YOLO](http://en.wikipedia.org/wiki/YOLO_(motto)', ('[YOLO](http://en.wikipedia.org/wiki/YOLO_(motto))',
# '') '<p><a href="http://en.wikipedia.org/wiki/YOLO_(motto)" target="_blank" title="http://en.wikipedia.org/wiki/YOLO_(motto)"\
>YOLO</a></p>')
) )
for input, output in urls: for input, output in urls: