Skip to content

Instantly share code, notes, and snippets.

@garywu
Created February 18, 2017 04:21
Show Gist options
  • Save garywu/90cb3ce62e611b021060e464fd58cb47 to your computer and use it in GitHub Desktop.
Save garywu/90cb3ce62e611b021060e464fd58cb47 to your computer and use it in GitHub Desktop.
# cheap immitation of %pycat
from IPython.core.display import display, HTML
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
def show(filename):
text = !cat $filename
text = '\n'.join(text)
html = highlight(text, PythonLexer(), HtmlFormatter())
display(HTML(html))
display(HTML("""
<style>
{pygments_css}
</style>
""".format(pygments_css=HtmlFormatter().get_style_defs('.highlight'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment