I like IPython’s Markdown cells for incorporating HTML and other rich content inside notebooks. I would like to know if a command output can be formatted similarly, in output cells.
Here is one of my functions outputting HTML:
print_html():
print """
<h2>Matplotlib's chart gallery (Click a chart to see the code to create it)</h2><br>
<div align="center"> <iframe title="Matplotlib Gallery" width="950"
height="250" src="http://matplotlib.org/gallery.html#api" frameborder="0"
allowfullscreen></iframe></div>
"""
The HTML code above, if placed in markdown (input) cell, produces nice link to the Matplotlib library. But in output cell it is just plain text. Any way to make it rich content?
Found a solution here: http://mail.scipy.org/pipermail/ipython-user/2012-April/009838.html
Quoting the solution here for ref:
Brian Granger:
”
Have the function return the raw HTML wrapped in an HTML object:
“
Now calling foo() does give rich formatted html as I wanted.