Mercurial > kallithea
annotate rhodecode/lib/markup_renderer.py @ 3893:7e9776f38c55 beta
fixed duplicated test in diff tests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 22 May 2013 22:35:39 +0200 |
parents | 01cb7df198ae |
children | 7563624e712c |
rev | line source |
---|---|
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.lib.markup_renderer |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
6 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 Renderer for markup languages with ability to parse using rst or markdown |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
8 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :created_on: Oct 27, 2011 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
11 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 :license: GPLv3, see COPYING for more details. |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # This program is free software: you can redistribute it and/or modify |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # it under the terms of the GNU General Public License as published by |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # the Free Software Foundation, either version 3 of the License, or |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # (at your option) any later version. |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # This program is distributed in the hope that it will be useful, |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # GNU General Public License for more details. |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # You should have received a copy of the GNU General Public License |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 import re |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import logging |
2747
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
29 import traceback |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
2201
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
31 from rhodecode.lib.utils2 import safe_unicode, MENTIONS_REGEX |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 log = logging.getLogger(__name__) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
1996
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
35 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 class MarkupRenderer(object): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw'] |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
38 |
1996
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
39 MARKDOWN_PAT = re.compile(r'md|mkdn?|mdown|markdown', re.IGNORECASE) |
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
40 RST_PAT = re.compile(r're?st', re.IGNORECASE) |
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
41 PLAIN_PAT = re.compile(r'readme', re.IGNORECASE) |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
42 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 def __detect_renderer(self, source, filename=None): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 runs detection of what renderer should be used for generating html |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 from a markup language |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
47 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 filename can be also explicitly a renderer name |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
49 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 :param source: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 :param filename: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 if MarkupRenderer.MARKDOWN_PAT.findall(filename): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 detected_renderer = 'markdown' |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 elif MarkupRenderer.RST_PAT.findall(filename): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 detected_renderer = 'rst' |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 elif MarkupRenderer.PLAIN_PAT.findall(filename): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 detected_renderer = 'rst' |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 else: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 detected_renderer = 'plain' |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 return getattr(MarkupRenderer, detected_renderer) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 def render(self, source, filename=None): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 Renders a given filename using detected renderer |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 it detects renderers based on file extension or mimetype. |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 At last it will just do a simple html replacing new lines with <br/> |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
70 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 :param file_name: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 :param source: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 """ |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 renderer = self.__detect_renderer(source, filename) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 readme_data = renderer(source) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 return readme_data |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 @classmethod |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 def plain(cls, source): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 source = safe_unicode(source) |
1996
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
82 |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 def urlify_text(text): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 url_pat = re.compile(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]' |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 '|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)') |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 def url_func(match_obj): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 url_full = match_obj.groups()[0] |
1996
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
89 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full}) |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 return url_pat.sub(url_func, text) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 source = urlify_text(source) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 return '<br />' + source.replace("\n", '<br />') |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 @classmethod |
2747
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
97 def markdown(cls, source, safe=True): |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 source = safe_unicode(source) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 try: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 import markdown as __markdown |
3164
01cb7df198ae
Enable all Markdown Extra in Python markdown library.
xpol <xpolife@gmail.com>
parents:
3019
diff
changeset
|
101 return __markdown.markdown(source, ['codehilite', 'extra']) |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 except ImportError: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 log.warning('Install markdown to use this function') |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 return cls.plain(source) |
2747
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
105 except Exception: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
106 log.error(traceback.format_exc()) |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
107 if safe: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
108 return source |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
109 else: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
110 raise |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 @classmethod |
2747
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
113 def rst(cls, source, safe=True): |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 source = safe_unicode(source) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 try: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 from docutils.core import publish_parts |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 from docutils.parsers.rst import directives |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 docutils_settings = dict([(alias, None) for alias in |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 cls.RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES]) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 docutils_settings.update({'input_encoding': 'unicode', |
1996
0592987973eb
activate codehilite extension on markdown renderer, inspired by bitbucket blog ;)
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
122 'report_level': 4}) |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 for k, v in docutils_settings.iteritems(): |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 directives.register_directive(k, v) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 parts = publish_parts(source=source, |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 writer_name="html4css1", |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 settings_overrides=docutils_settings) |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 return parts['html_title'] + parts["fragment"] |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 except ImportError: |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 log.warning('Install docutils to use this function') |
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 return cls.plain(source) |
2747
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
135 except Exception: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
136 log.error(traceback.format_exc()) |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
137 if safe: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
138 return source |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
139 else: |
cdce3d7282b2
catch errors on renderers, and display plain if critical rendering error is present
Marcin Kuzminski <marcin@python-works.com>
parents:
2201
diff
changeset
|
140 raise |
1604
bb3c2111bf92
initial version of markup renderer
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 |
1769
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
142 @classmethod |
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
143 def rst_with_mentions(cls, source): |
2201
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
144 mention_pat = re.compile(MENTIONS_REGEX) |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1769
diff
changeset
|
145 |
1769
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
146 def wrapp(match_obj): |
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
147 uname = match_obj.groups()[0] |
2201
ea5ff843b200
#426 fixed mention extracting regex
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
148 return ' **@%(uname)s** ' % {'uname': uname} |
1769
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
149 mention_hl = mention_pat.sub(wrapp, source).strip() |
025f3333c769
@mention highlighting
Marcin Kuzminski <marcin@python-works.com>
parents:
1604
diff
changeset
|
150 return cls.rst(mention_hl) |