Mercurial > public > sg101
annotate core/markup.py @ 698:efb525863a75
jQuery UI Tabs were changed quite a bit, which broke private messages.
Here is a fix. Upgrade notes are found here:
http://jqueryui.com/upgrade-guide/1.9/#tabs
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 09 Sep 2013 20:30:13 -0500 |
parents | 216f06267e2d |
children | 7429c98c8ece |
rev | line source |
---|---|
bgneal@124 | 1 """ |
bgneal@128 | 2 Markup related utitlities useful for the entire project. |
bgneal@124 | 3 """ |
bgneal@124 | 4 import markdown as _markdown |
bgneal@124 | 5 from django.utils.encoding import force_unicode |
bgneal@124 | 6 |
bgneal@211 | 7 from smiley import SmilifyMarkdown |
bgneal@124 | 8 |
bgneal@124 | 9 class Markdown(object): |
bgneal@128 | 10 """ |
bgneal@128 | 11 This is a thin wrapper around the Markdown class which deals with the |
bgneal@128 | 12 differences in Markdown versions on the production and development server. |
bgneal@352 | 13 This code was inspired by the code in |
bgneal@128 | 14 django/contrib/markup/templatetags/markup.py. |
bgneal@128 | 15 Currently, we only have to worry about Markdown 1.6b and 2.0. |
bgneal@128 | 16 """ |
bgneal@124 | 17 def __init__(self, safe_mode='escape'): |
bgneal@353 | 18 self.md = _markdown.Markdown(safe_mode=safe_mode, |
bgneal@356 | 19 extensions=['urlize', 'nl2br', 'del']) |
bgneal@124 | 20 |
bgneal@124 | 21 def convert(self, s): |
bgneal@686 | 22 return self.md.convert(force_unicode(s)) |
bgneal@124 | 23 |
bgneal@124 | 24 |
bgneal@124 | 25 def markdown(s): |
bgneal@128 | 26 """ |
bgneal@128 | 27 A convenience function for one-off markdown jobs. |
bgneal@128 | 28 """ |
bgneal@124 | 29 md = Markdown() |
bgneal@124 | 30 return md.convert(s) |
bgneal@128 | 31 |
bgneal@128 | 32 |
bgneal@128 | 33 class SiteMarkup(object): |
bgneal@128 | 34 """ |
bgneal@128 | 35 This class provides site markup by combining markdown and |
bgneal@128 | 36 our own smiley markup. |
bgneal@128 | 37 """ |
bgneal@128 | 38 def __init__(self): |
bgneal@128 | 39 self.md = Markdown() |
bgneal@211 | 40 self.smiley = SmilifyMarkdown() |
bgneal@128 | 41 |
bgneal@128 | 42 def convert(self, s): |
bgneal@211 | 43 return self.md.convert(self.smiley.convert(s)) |
bgneal@128 | 44 |
bgneal@128 | 45 |
bgneal@128 | 46 def site_markup(s): |
bgneal@128 | 47 """ |
bgneal@128 | 48 Convenience function for one-off site markup jobs. |
bgneal@128 | 49 """ |
bgneal@128 | 50 sm = SiteMarkup() |
bgneal@128 | 51 return sm.convert(s) |