Mercurial > public > sg101
changeset 356:f54bf3b3bece
Fix 180; Add strikethrough capability to markdown via an extension. Also control in SVN the extensions we are using.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 04 Mar 2011 02:10:37 +0000 |
parents | a1e3724f0799 |
children | 8e3f252e4fbb |
files | gpp/core/markup.py gpp/templates/core/markdown_help.html static/js/markitup/sets/markdown/images/strike.png static/js/markitup/sets/markdown/set.js static/js/markitup/sets/markdown/style.css tools/mdx_del.py tools/mdx_nl2br.py tools/mdx_urlize.py |
diffstat | 8 files changed, 138 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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:
--- 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 @@ <td><pre>###### Header 6</pre></td> <td><h6>Header 6</h6></td> </tr> + <tr> + <th>Strikethrough</th> + <td><pre>--This text is deleted--</pre></td> + <td><del>This text is deleted</del></td> + </tr> </table> <p> More help:
--- 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) {
--- 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); }
--- /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 <del>. +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)
--- /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)
--- /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'<p><a href="http://example.com/">http://example.com/</a></p>' + +>>> md.convert('go to http://example.com') +u'<p>go to <a href="http://example.com">http://example.com</a></p>' + +>>> md.convert('example.com') +u'<p><a href="http://example.com">example.com</a></p>' + +>>> md.convert('example.net') +u'<p><a href="http://example.net">example.net</a></p>' + +>>> md.convert('www.example.us') +u'<p><a href="http://www.example.us">www.example.us</a></p>' + +>>> md.convert('(www.example.us/path/?name=val)') +u'<p>(<a href="http://www.example.us/path/?name=val">www.example.us/path/?name=val</a>)</p>' + +>>> md.convert('go to <http://example.com> now!') +u'<p>go to <a href="http://example.com">http://example.com</a> now!</p>' + +Negative examples: + +>>> md.convert('del.icio.us') +u'<p>del.icio.us</p>' + +""" + +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()