##// END OF EJS Templates
markup-renderer: use global Markdown object to speed up markdown rendering.
marcink -
r1353:7b18aa9b default
parent child Browse files
Show More
@@ -51,6 +51,14 b' class MarkupRenderer(object):'
51 RST_PAT = re.compile(r'\.re?st$', re.IGNORECASE)
51 RST_PAT = re.compile(r'\.re?st$', re.IGNORECASE)
52 PLAIN_PAT = re.compile(r'^readme$', re.IGNORECASE)
52 PLAIN_PAT = re.compile(r'^readme$', re.IGNORECASE)
53
53
54 extensions = ['codehilite', 'extra', 'def_list', 'sane_lists']
55 markdown_renderer = markdown.Markdown(
56 extensions, safe_mode=True, enable_attributes=False)
57
58 markdown_renderer_flavored = markdown.Markdown(
59 extensions + [GithubFlavoredMarkdownExtension()], safe_mode=True,
60 enable_attributes=False)
61
54 # extension together with weights. Lower is first means we control how
62 # extension together with weights. Lower is first means we control how
55 # extensions are attached to readme names with those.
63 # extensions are attached to readme names with those.
56 PLAIN_EXTS = [
64 PLAIN_EXTS = [
@@ -188,9 +196,11 b' class MarkupRenderer(object):'
188 # It does not allow to insert inline HTML. In presence of HTML tags, it
196 # It does not allow to insert inline HTML. In presence of HTML tags, it
189 # will replace them instead with [HTML_REMOVED]. This is controlled by
197 # will replace them instead with [HTML_REMOVED]. This is controlled by
190 # the safe_mode=True parameter of the markdown method.
198 # the safe_mode=True parameter of the markdown method.
191 extensions = ['codehilite', 'extra', 'def_list', 'sane_lists']
199
192 if flavored:
200 if flavored:
193 extensions.append(GithubFlavoredMarkdownExtension())
201 markdown_renderer = cls.markdown_renderer_flavored
202 else:
203 markdown_renderer = cls.markdown_renderer
194
204
195 if mentions:
205 if mentions:
196 mention_pat = re.compile(MENTIONS_REGEX)
206 mention_pat = re.compile(MENTIONS_REGEX)
@@ -207,8 +217,7 b' class MarkupRenderer(object):'
207 try:
217 try:
208 if flavored:
218 if flavored:
209 source = cls._flavored_markdown(source)
219 source = cls._flavored_markdown(source)
210 return markdown.markdown(
220 return markdown_renderer.convert(source)
211 source, extensions, safe_mode=True, enable_attributes=False)
212 except Exception:
221 except Exception:
213 log.exception('Error when rendering Markdown')
222 log.exception('Error when rendering Markdown')
214 if safe:
223 if safe:
General Comments 0
You need to be logged in to leave comments. Login now