Mercurial > public > sg101
diff gpp/core/markup.py @ 128:48621ba5c385
Fixing #36, Smilify doesn't work when a smiley appears first before other text. Refactored the smiley system to produce markdown as well as HTML.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 20 Nov 2009 01:43:32 +0000 |
parents | 9c18250972d5 |
children | 3a626c48e9ae |
line wrap: on
line diff
--- a/gpp/core/markup.py Mon Nov 16 01:00:28 2009 +0000 +++ b/gpp/core/markup.py Fri Nov 20 01:43:32 2009 +0000 @@ -1,17 +1,19 @@ """ -This is a thin wrapper around the Markdown class which deals with the -differences in Markdown versions on the production and development server. -This code was inspired by the code in -django/contrib/markup/templatetags/markup.py. -Currently, we only have to worry about Markdown 1.6b and 2.0. +Markup related utitlities useful for the entire project. """ import markdown as _markdown from django.utils.encoding import force_unicode -from smiley.utils import smilify +from smiley import Smilify class Markdown(object): - + """ + This is a thin wrapper around the Markdown class which deals with the + differences in Markdown versions on the production and development server. + This code was inspired by the code in + django/contrib/markup/templatetags/markup.py. + Currently, we only have to worry about Markdown 1.6b and 2.0. + """ def __init__(self, safe_mode='escape'): # Unicode support only in markdown v1.7 or above. Version_info # exists only in markdown v1.6.2rc-2 or above. @@ -26,5 +28,29 @@ def markdown(s): + """ + A convenience function for one-off markdown jobs. + """ md = Markdown() return md.convert(s) + + +class SiteMarkup(object): + """ + This class provides site markup by combining markdown and + our own smiley markup. + """ + def __init__(self): + self.md = Markdown() + self.smiley = Smilify() + + def convert(self, s): + return self.md.convert(self.smiley.markdown(s)) + + +def site_markup(s): + """ + Convenience function for one-off site markup jobs. + """ + sm = SiteMarkup() + return sm.convert(s)