The pygments_magic extension allows you to display source code files in IPython with syntax highlighting. It requires the Pygments library.
It can be installed with:
%install_ext https://gist.github.com/jiffyclub/5385501/raw/pygments_magic.py
%load_ext pygments_magic
The %highlight
magic uses terminal color codes and will work in any of IPython's front ends.
%highlight ipython_rocks.py
from __future__ import print_function def ipython_rocks(): """Yes, yes it does.""" print('IPython rocks!') ipython_rocks()
The %highlight_html
magic outputs HTML and is best used in the Notebook. %highlight_html
can show line numbers or display with any avaiable
Pygments style. See these previews for some examples.
%highlight_html -n ipython_rocks.py
1 2 3 4 5 6 7 | from __future__ import print_function def ipython_rocks(): """Yes, yes it does.""" print('IPython rocks!') ipython_rocks() |
%highlight_html -s monokai ipython_rocks.py
from __future__ import print_function def ipython_rocks(): """Yes, yes it does.""" print('IPython rocks!') ipython_rocks()