def display_source_ipython(self):
"""
Convenience method to print the loaded source file
as syntax highlighted HTML within IPython.
"""
from pygments import highlight
from pygments.lexers import SLexer
from pygments.formatters import HtmlFormatter
import IPython.display as display
with open(self.source_file) as f:
code = f.read()
formatter = HtmlFormatter()
return display.HTML('<style type="text/css">{}</style>{}'.format(
formatter.get_style_defs('.highlight'),
highlight(code, SLexer(), formatter)))
评论列表
文章目录