annotate core/markup.py @ 798:c5d73b4a2899

New Fred Lammers Surf Music Madrid logo.
author Brian Neal <bgneal@gmail.com>
date Sat, 12 Jul 2014 16:33:07 -0500
parents 7429c98c8ece
children 32ebe22f0cad
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@792 11 This is a thin wrapper around the Markdown class.
bgneal@792 12
bgneal@128 13 """
bgneal@124 14 def __init__(self, safe_mode='escape'):
bgneal@353 15 self.md = _markdown.Markdown(safe_mode=safe_mode,
bgneal@356 16 extensions=['urlize', 'nl2br', 'del'])
bgneal@124 17
bgneal@124 18 def convert(self, s):
bgneal@686 19 return self.md.convert(force_unicode(s))
bgneal@124 20
bgneal@124 21
bgneal@124 22 def markdown(s):
bgneal@128 23 """
bgneal@128 24 A convenience function for one-off markdown jobs.
bgneal@128 25 """
bgneal@124 26 md = Markdown()
bgneal@124 27 return md.convert(s)
bgneal@128 28
bgneal@128 29
bgneal@128 30 class SiteMarkup(object):
bgneal@128 31 """
bgneal@128 32 This class provides site markup by combining markdown and
bgneal@128 33 our own smiley markup.
bgneal@792 34
bgneal@792 35 The relative_urls parameter controls whether the smileys are generated with
bgneal@792 36 relative or absolute URLs.
bgneal@792 37
bgneal@128 38 """
bgneal@792 39 def __init__(self, relative_urls=True):
bgneal@128 40 self.md = Markdown()
bgneal@792 41 self.smiley = SmilifyMarkdown(relative_urls=relative_urls)
bgneal@128 42
bgneal@128 43 def convert(self, s):
bgneal@211 44 return self.md.convert(self.smiley.convert(s))
bgneal@128 45
bgneal@128 46
bgneal@792 47 def site_markup(s, relative_urls=True):
bgneal@128 48 """
bgneal@128 49 Convenience function for one-off site markup jobs.
bgneal@128 50 """
bgneal@792 51 sm = SiteMarkup(relative_urls=relative_urls)
bgneal@128 52 return sm.convert(s)