From 5a41ea00e01e26de9db9126cef55706ce2800b53 Mon Sep 17 00:00:00 2001 From: ap-Codkelden Date: Mon, 20 Apr 2015 01:45:00 +0300 Subject: [PATCH] Redefine sanitize_url method of the standart LinkPattern class because of Twitter use 'size' attribute in pics and other media enitities, see https://dev.twitter.com/overview/api/entities-in-twitter-objects --- markdown/inlinepatterns.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 95d358d71..22d443727 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -410,9 +410,12 @@ def sanitize_url(self, url): for part in url[2:]: if ":" in part: - # A colon in "path", "parameters", "query" - # or "fragment" is suspect. - return '' + # Check if this is just Twitter media link with 'size' + colon_regex = re.compile('[/\w]*?\.(jpe?g|png|gif)(:large)?') + if not colon_regex.match(part): + # If not -- a colon in "path", "parameters", "query" + # or "fragment" is suspect. + return '' # Url passes all tests. Return url as-is. return urlunparse(url)