##// END OF EJS Templates
Add highlighting of GFM code blocks with mistune
Thomas Kluyver -
Show More
@@ -90,8 +90,22 b' def markdown2html(source):'
90 else:
90 else:
91 return markdown2html_pandoc(source)
91 return markdown2html_pandoc(source)
92
92
93 if mistune is not None:
94 from pygments import highlight
95 from pygments.lexers import get_lexer_by_name
96 from pygments.formatters import HtmlFormatter
97
98 class MyRenderer(mistune.Renderer):
99 def block_code(self, code, lang):
100 if not lang:
101 return '\n<pre><code>%s</code></pre>\n' % \
102 mistune.escape(code)
103 lexer = get_lexer_by_name(lang, stripall=True)
104 formatter = HtmlFormatter()
105 return highlight(code, lexer, formatter)
106
93 def markdown2html_mistune(source):
107 def markdown2html_mistune(source):
94 return mistune.markdown(source)
108 return mistune.Markdown(renderer=MyRenderer()).render(source)
95
109
96 def markdown2html_pandoc(source):
110 def markdown2html_pandoc(source):
97 """Convert a markdown string to HTML via pandoc"""
111 """Convert a markdown string to HTML via pandoc"""
General Comments 0
You need to be logged in to leave comments. Login now