diff options
Diffstat (limited to 'glifestream/utils/html.py')
-rw-r--r-- | glifestream/utils/html.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/glifestream/utils/html.py b/glifestream/utils/html.py index 9ff2658..d37780e 100644 --- a/glifestream/utils/html.py +++ b/glifestream/utils/html.py @@ -60,17 +60,20 @@ def strip_entities(value): strip_entities = allow_lazy(strip_entities, six.text_type) -## -## Code taken from Django 1.7 -## +# +# Code taken from Django 1.7 +# TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', '\''] -WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>'), ('"', '"'), ('\'', '\'')] +WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), + ('<', '>'), ('"', '"'), ('\'', '\'')] word_split_re = re.compile(r'(\s+)') simple_url_re = re.compile(r'^https?://\[?\w', re.IGNORECASE) -simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE) +simple_url_2_re = re.compile( + r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE) simple_email_re = re.compile(r'^\S+@\S+\.\S+$') + def smart_urlquote(url): "Quotes a URL if it isn't already quoted." # Handle IDN before quoting. @@ -91,6 +94,7 @@ def smart_urlquote(url): return force_text(url) + def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): """ Converts any URLs in text into clickable links. @@ -154,7 +158,8 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): if autoescape and not safe_input: lead, trail = escape(lead), escape(trail) url, trimmed = escape(url), escape(trimmed) - middle = '<a href="%s"%s>%s</a>' % (url, nofollow_attr, trimmed) + middle = '<a href="%s"%s>%s</a>' % (url, + nofollow_attr, trimmed) words[i] = mark_safe('%s%s%s' % (lead, middle, trail)) else: if safe_input: @@ -166,4 +171,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): elif autoescape: words[i] = escape(word) return ''.join(words) + + urlize = allow_lazy(urlize, six.text_type) |