bgneal@124: """ bgneal@124: This is a thin wrapper around the Markdown class which deals with the bgneal@124: differences in Markdown versions on the production and development server. bgneal@124: This code was inspired by the code in bgneal@124: django/contrib/markup/templatetags/markup.py. bgneal@124: Currently, we only have to worry about Markdown 1.6b and 2.0. bgneal@124: """ bgneal@124: import markdown as _markdown bgneal@124: from django.utils.encoding import force_unicode bgneal@124: bgneal@124: from smiley.utils import smilify bgneal@124: bgneal@124: class Markdown(object): bgneal@124: bgneal@124: def __init__(self, safe_mode='escape'): bgneal@124: # Unicode support only in markdown v1.7 or above. Version_info bgneal@124: # exists only in markdown v1.6.2rc-2 or above. bgneal@124: self.unicode_support = getattr(_markdown, "version_info", None) >= (1, 7) bgneal@124: self.md = _markdown.Markdown(safe_mode=safe_mode) bgneal@124: bgneal@124: def convert(self, s): bgneal@124: if self.unicode_support: bgneal@124: return self.md.convert(force_unicode(s)) bgneal@124: else: bgneal@124: return force_unicode(self.md.convert(s)) bgneal@124: bgneal@124: bgneal@124: def markdown(s): bgneal@124: md = Markdown() bgneal@124: return md.convert(s)