##// END OF EJS Templates
Fix code block rendering when lexer not known
Thomas Kluyver -
Show More
@@ -25,6 +25,7 b' import mistune'
25 25 from pygments import highlight
26 26 from pygments.lexers import get_lexer_by_name
27 27 from pygments.formatters import HtmlFormatter
28 from pygments.util import ClassNotFound
28 29
29 30 # IPython imports
30 31 from IPython.nbconvert.utils.pandoc import pandoc
@@ -118,10 +119,17 b' class MarkdownWithMath(mistune.Markdown):'
118 119
119 120 class IPythonRenderer(mistune.Renderer):
120 121 def block_code(self, code, lang):
122 if lang:
123 try:
124 lexer = get_lexer_by_name(lang, stripall=True)
125 except ClassNotFound:
126 code = lang + '\n' + code
127 lang = None
128
121 129 if not lang:
122 130 return '\n<pre><code>%s</code></pre>\n' % \
123 131 mistune.escape(code)
124 lexer = get_lexer_by_name(lang, stripall=True)
132
125 133 formatter = HtmlFormatter()
126 134 return highlight(code, lexer, formatter)
127 135
General Comments 0
You need to be logged in to leave comments. Login now