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