@shaun do you happen to know if there is a way to achieve syntax highlighting so
```python
print(“help”)
```
becomes
print("help")
If we had the module pygments we could have something like the following so we could get syntax highlighting.
text="""```python\nprint("help")\n```"""
import mistune
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import html
class HighlightRenderer(mistune.Renderer):
def block_code(self, code, lang):
if not lang:
return '\n<pre><code>%s</code></pre>\n' % \
mistune.escape(code)
lexer = get_lexer_by_name(lang, stripall=True)
formatter = html.HtmlFormatter()
return highlight(code, lexer, formatter)
renderer = HighlightRenderer()
markdown = mistune.Markdown(renderer=renderer)
print(markdown(text))
output:
<div class="highlight"><pre><span></span><span class="k">print</span><span class="p">(</span><span class="s2">"help"</span><span class="p">)</span>
</pre></div>