Mercurial > public > sg101
comparison core/markup.py @ 792:7429c98c8ece
Issue #71: use relative URLs for smileys on the web and absolute for RSS.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 26 May 2014 14:59:55 -0500 |
parents | 216f06267e2d |
children | 32ebe22f0cad |
comparison
equal
deleted
inserted
replaced
791:0ca691cccf8d | 792:7429c98c8ece |
---|---|
6 | 6 |
7 from smiley import SmilifyMarkdown | 7 from smiley import SmilifyMarkdown |
8 | 8 |
9 class Markdown(object): | 9 class Markdown(object): |
10 """ | 10 """ |
11 This is a thin wrapper around the Markdown class which deals with the | 11 This is a thin wrapper around the Markdown class. |
12 differences in Markdown versions on the production and development server. | 12 |
13 This code was inspired by the code in | |
14 django/contrib/markup/templatetags/markup.py. | |
15 Currently, we only have to worry about Markdown 1.6b and 2.0. | |
16 """ | 13 """ |
17 def __init__(self, safe_mode='escape'): | 14 def __init__(self, safe_mode='escape'): |
18 self.md = _markdown.Markdown(safe_mode=safe_mode, | 15 self.md = _markdown.Markdown(safe_mode=safe_mode, |
19 extensions=['urlize', 'nl2br', 'del']) | 16 extensions=['urlize', 'nl2br', 'del']) |
20 | 17 |
32 | 29 |
33 class SiteMarkup(object): | 30 class SiteMarkup(object): |
34 """ | 31 """ |
35 This class provides site markup by combining markdown and | 32 This class provides site markup by combining markdown and |
36 our own smiley markup. | 33 our own smiley markup. |
34 | |
35 The relative_urls parameter controls whether the smileys are generated with | |
36 relative or absolute URLs. | |
37 | |
37 """ | 38 """ |
38 def __init__(self): | 39 def __init__(self, relative_urls=True): |
39 self.md = Markdown() | 40 self.md = Markdown() |
40 self.smiley = SmilifyMarkdown() | 41 self.smiley = SmilifyMarkdown(relative_urls=relative_urls) |
41 | 42 |
42 def convert(self, s): | 43 def convert(self, s): |
43 return self.md.convert(self.smiley.convert(s)) | 44 return self.md.convert(self.smiley.convert(s)) |
44 | 45 |
45 | 46 |
46 def site_markup(s): | 47 def site_markup(s, relative_urls=True): |
47 """ | 48 """ |
48 Convenience function for one-off site markup jobs. | 49 Convenience function for one-off site markup jobs. |
49 """ | 50 """ |
50 sm = SiteMarkup() | 51 sm = SiteMarkup(relative_urls=relative_urls) |
51 return sm.convert(s) | 52 return sm.convert(s) |