# HG changeset patch # User Brian Neal # Date 1299204637 0 # Node ID f54bf3b3bece97975412c8e5a5952ca4ee679b89 # Parent a1e3724f0799c76307d0aa6e0cab44530c45bfab Fix 180; Add strikethrough capability to markdown via an extension. Also control in SVN the extensions we are using. diff -r a1e3724f0799 -r f54bf3b3bece gpp/core/markup.py --- a/gpp/core/markup.py Fri Mar 04 01:34:43 2011 +0000 +++ b/gpp/core/markup.py Fri Mar 04 02:10:37 2011 +0000 @@ -19,7 +19,7 @@ # exists only in markdown v1.6.2rc-2 or above. self.unicode_support = getattr(_markdown, "version_info", None) >= (1, 7) self.md = _markdown.Markdown(safe_mode=safe_mode, - extensions=['urlize', 'nl2br']) + extensions=['urlize', 'nl2br', 'del']) def convert(self, s): if self.unicode_support: diff -r a1e3724f0799 -r f54bf3b3bece gpp/templates/core/markdown_help.html --- a/gpp/templates/core/markdown_help.html Fri Mar 04 01:34:43 2011 +0000 +++ b/gpp/templates/core/markdown_help.html Fri Mar 04 02:10:37 2011 +0000 @@ -157,6 +157,11 @@
###### Header 6
Header 6
+ + Strikethrough +
--This text is deleted--
+ This text is deleted +

More help: diff -r a1e3724f0799 -r f54bf3b3bece static/js/markitup/sets/markdown/images/strike.png Binary file static/js/markitup/sets/markdown/images/strike.png has changed diff -r a1e3724f0799 -r f54bf3b3bece static/js/markitup/sets/markdown/set.js --- a/static/js/markitup/sets/markdown/set.js Fri Mar 04 01:34:43 2011 +0000 +++ b/static/js/markitup/sets/markdown/set.js Fri Mar 04 02:10:37 2011 +0000 @@ -20,6 +20,7 @@ markupSet: [ {name:'Bold', key:'B', openWith:'**', closeWith:'**'}, {name:'Italic', key:'I', openWith:'_', closeWith:'_'}, + {name:'Strike', key:'S', openWith:'--', closeWith:'--'}, {separator:'---------------' }, {name:'Bulleted List', openWith:'- ' }, {name:'Numeric List', openWith:function(markItUp) { diff -r a1e3724f0799 -r f54bf3b3bece static/js/markitup/sets/markdown/style.css --- a/static/js/markitup/sets/markdown/style.css Fri Mar 04 01:34:43 2011 +0000 +++ b/static/js/markitup/sets/markdown/style.css Fri Mar 04 02:10:37 2011 +0000 @@ -8,25 +8,28 @@ .markItUp .markItUpButton2 a { background-image:url(images/italic.png); } +.markItUp .markItUpButton3 a { + background-image:url(images/strike.png); +} -.markItUp .markItUpButton3 a { +.markItUp .markItUpButton4 a { background-image:url(images/list-bullet.png); } -.markItUp .markItUpButton4 a { +.markItUp .markItUpButton5 a { background-image:url(images/list-numeric.png); } -.markItUp .markItUpButton5 a { +.markItUp .markItUpButton6 a { background-image:url(images/picture.png); } -.markItUp .markItUpButton6 a { +.markItUp .markItUpButton7 a { background-image:url(images/link.png); } -.markItUp .markItUpButton7 a { +.markItUp .markItUpButton8 a { background-image:url(images/quotes.png); } -.markItUp .markItUpButton8 a { +.markItUp .markItUpButton9 a { background-image:url(images/code.png); } diff -r a1e3724f0799 -r f54bf3b3bece tools/mdx_del.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mdx_del.py Fri Mar 04 02:10:37 2011 +0000 @@ -0,0 +1,19 @@ +""" +A python-markdown extension to add support for . +The Markdown syntax is --this is deleted text--. + +""" +import markdown + + +DEL_RE = r'(--)(.*?)--' + +class DelExtension(markdown.Extension): + + def extendMarkdown(self, md, md_globals): + del_tag = markdown.inlinepatterns.SimpleTagPattern(DEL_RE, 'del') + md.inlinePatterns.add('del', del_tag, '>not_strong') + + +def makeExtension(configs=None): + return DelExtension(configs) diff -r a1e3724f0799 -r f54bf3b3bece tools/mdx_nl2br.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mdx_nl2br.py Fri Mar 04 02:10:37 2011 +0000 @@ -0,0 +1,19 @@ +""" +A python-markdown extension to treat newlines as hard breaks; like +StackOverflow and GitHub flavored Markdown do. + +""" +import markdown + + +BR_RE = r'\n' + +class Nl2BrExtension(markdown.Extension): + + def extendMarkdown(self, md, md_globals): + br_tag = markdown.inlinepatterns.SubstituteTagPattern(BR_RE, 'br') + md.inlinePatterns.add('nl', br_tag, '_end') + + +def makeExtension(configs=None): + return Nl2BrExtension(configs) diff -r a1e3724f0799 -r f54bf3b3bece tools/mdx_urlize.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mdx_urlize.py Fri Mar 04 02:10:37 2011 +0000 @@ -0,0 +1,84 @@ +""" +Taken from: https://github.com/r0wb0t/markdown-urlize + +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.etree.Element("a") + el.set('href', url) + el.text = markdown.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()