Mercurial > public > sg101
comparison gpp/core/markup.py @ 124:9c18250972d5
Refactored the markdown/smiley logic. Created classes for Markdown and Smilify. No longer call render_to_string() in models.py for various models.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Nov 2009 04:32:32 +0000 |
parents | |
children | 48621ba5c385 |
comparison
equal
deleted
inserted
replaced
123:3ae999b0c53b | 124:9c18250972d5 |
---|---|
1 """ | |
2 This is a thin wrapper around the Markdown class which deals with the | |
3 differences in Markdown versions on the production and development server. | |
4 This code was inspired by the code in | |
5 django/contrib/markup/templatetags/markup.py. | |
6 Currently, we only have to worry about Markdown 1.6b and 2.0. | |
7 """ | |
8 import markdown as _markdown | |
9 from django.utils.encoding import force_unicode | |
10 | |
11 from smiley.utils import smilify | |
12 | |
13 class Markdown(object): | |
14 | |
15 def __init__(self, safe_mode='escape'): | |
16 # Unicode support only in markdown v1.7 or above. Version_info | |
17 # exists only in markdown v1.6.2rc-2 or above. | |
18 self.unicode_support = getattr(_markdown, "version_info", None) >= (1, 7) | |
19 self.md = _markdown.Markdown(safe_mode=safe_mode) | |
20 | |
21 def convert(self, s): | |
22 if self.unicode_support: | |
23 return self.md.convert(force_unicode(s)) | |
24 else: | |
25 return force_unicode(self.md.convert(s)) | |
26 | |
27 | |
28 def markdown(s): | |
29 md = Markdown() | |
30 return md.convert(s) |