##// END OF EJS Templates
markdown-renderer: use lazy loaded markdown renderers initialization....
marcink -
r3239:1b708774 default
parent child Browse files
Show More
@@ -40,8 +40,7 b' from docutils.writers import html4css1'
40 40 import markdown
41 41
42 42 from rhodecode.lib.markdown_ext import GithubFlavoredMarkdownExtension
43 from rhodecode.lib.utils2 import (
44 safe_str, safe_unicode, md5_safe, MENTIONS_REGEX)
43 from rhodecode.lib.utils2 import (safe_unicode, md5_safe, MENTIONS_REGEX)
45 44
46 45 log = logging.getLogger(__name__)
47 46
@@ -172,6 +171,32 b' def relative_path(path, request_path, is'
172 171 return u'/' + final_path
173 172
174 173
174 _cached_markdown_renderer = None
175
176
177 def get_markdown_renderer(extensions, output_format):
178 global _cached_markdown_renderer
179
180 if _cached_markdown_renderer is None:
181 _cached_markdown_renderer = markdown.Markdown(
182 extensions=extensions,
183 enable_attributes=False, output_format=output_format)
184 return _cached_markdown_renderer
185
186
187 _cached_markdown_renderer_flavored = None
188
189
190 def get_markdown_renderer_flavored(extensions, output_format):
191 global _cached_markdown_renderer_flavored
192
193 if _cached_markdown_renderer_flavored is None:
194 _cached_markdown_renderer_flavored = markdown.Markdown(
195 extensions=extensions + [GithubFlavoredMarkdownExtension()],
196 enable_attributes=False, output_format=output_format)
197 return _cached_markdown_renderer_flavored
198
199
175 200 class MarkupRenderer(object):
176 201 RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw']
177 202
@@ -183,14 +208,10 b' class MarkupRenderer(object):'
183 208 URL_PAT = re.compile(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]'
184 209 r'|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)')
185 210
186 extensions = ['codehilite', 'extra', 'def_list', 'sane_lists']
211 extensions = ['markdown.extensions.codehilite', 'markdown.extensions.extra',
212 'markdown.extensions.def_list', 'markdown.extensions.sane_lists']
213
187 214 output_format = 'html4'
188 markdown_renderer = markdown.Markdown(
189 extensions, enable_attributes=False, output_format=output_format)
190
191 markdown_renderer_flavored = markdown.Markdown(
192 extensions + [GithubFlavoredMarkdownExtension()],
193 enable_attributes=False, output_format=output_format)
194 215
195 216 # extension together with weights. Lower is first means we control how
196 217 # extensions are attached to readme names with those.
@@ -346,9 +367,11 b' class MarkupRenderer(object):'
346 367 """
347 368
348 369 if flavored:
349 markdown_renderer = cls.markdown_renderer_flavored
370 markdown_renderer = get_markdown_renderer_flavored(
371 cls.extensions, cls.output_format)
350 372 else:
351 markdown_renderer = cls.markdown_renderer
373 markdown_renderer = get_markdown_renderer(
374 cls.extensions, cls.output_format)
352 375
353 376 if mentions:
354 377 mention_pat = re.compile(MENTIONS_REGEX)
@@ -452,7 +475,7 b' class MarkupRenderer(object):'
452 475
453 476 return nb, resources
454 477
455 def _sanitize_resources(resources):
478 def _sanitize_resources(input_resources):
456 479 """
457 480 Skip/sanitize some of the CSS generated and included in jupyter
458 481 so it doesn't messes up UI so much
@@ -464,8 +487,8 b' class MarkupRenderer(object):'
464 487 # _default_template_path_default, to achieve that
465 488
466 489 # strip the reset CSS
467 resources[0] = resources[0][resources[0].find('/*! Source'):]
468 return resources
490 input_resources[0] = input_resources[0][input_resources[0].find('/*! Source'):]
491 return input_resources
469 492
470 493 def as_html(notebook):
471 494 conf = Config()
General Comments 0
You need to be logged in to leave comments. Login now