From d2db3633ccdc70098b04eea25492327bcb82b685 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 9 May 2018 09:39:48 -0400 Subject: Changed Notes app to be simpler --- app/notes/mdx_urlize.py | 81 ------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 app/notes/mdx_urlize.py (limited to 'app/notes/mdx_urlize.py') diff --git a/app/notes/mdx_urlize.py b/app/notes/mdx_urlize.py deleted file mode 100644 index dc8d1d7..0000000 --- a/app/notes/mdx_urlize.py +++ /dev/null @@ -1,81 +0,0 @@ -"""A more liberal autolinker - -Inspired by Django's urlize function. - -Positive examples: - ->>> import markdown ->>> md = markdown.Markdown(extensions=['urlize']) - ->>> md.convert('http://example.com/') -u'

http://example.com/

' - ->>> md.convert('go to http://example.com') -u'

go to http://example.com

' - ->>> md.convert('example.com') -u'

example.com

' - ->>> md.convert('example.net') -u'

example.net

' - ->>> md.convert('www.example.us') -u'

www.example.us

' - ->>> md.convert('(www.example.us/path/?name=val)') -u'

(www.example.us/path/?name=val)

' - ->>> md.convert('go to now!') -u'

go to http://example.com now!

' - -Negative examples: - ->>> md.convert('del.icio.us') -u'

del.icio.us

' - -""" - -import markdown - -# Global Vars -URLIZE_RE = '(%s)' % '|'.join([ - r'<(?:f|ht)tps?://[^>]*>', - r'\b(?:f|ht)tps?://[^)<>\s]+[^.,)<>\s]', - r'\bwww\.[^)<>\s]+[^.,)<>\s]', - r'[^(<\s]+\.(?:com|net|org)\b', -]) - -class UrlizePattern(markdown.inlinepatterns.Pattern): - """ Return a link Element given an autolink (`http://example/com`). """ - def handleMatch(self, m): - url = m.group(2) - - if url.startswith('<'): - url = url[1:-1] - - text = url - - if not url.split('://')[0] in ('http','https','ftp'): - if '@' in url and not '/' in url: - url = 'mailto:' + url - else: - url = 'http://' + url - - el = markdown.util.etree.Element("a") - el.set('href', url) - el.text = markdown.util.AtomicString(text) - return el - -class UrlizeExtension(markdown.Extension): - """ Urlize Extension for Python-Markdown. """ - - def extendMarkdown(self, md, md_globals): - """ Replace autolink with UrlizePattern """ - md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md) - -def makeExtension(configs=None): - return UrlizeExtension(configs=configs) - -if __name__ == "__main__": - import doctest - doctest.testmod() -- cgit v1.2.3-70-g09d2