Since I've been been working in IPython Notebook a lot lately, I wanted to find a way to post Notebooks directly into a WordPress blog. The results I found by googling were only partially satisifactory:
http://stackoverflow.com/questions/20849988/posting-ipython-notebook-in-wordpress. This and #1 are essentially the same. They work, but since the html they start with is produced using the basic template of nbconvert, they leave out syntax highlighting and other important features.
http://onsnetwork.org/eimd/2014/08/08/how-to-enter-ipython-notebooks-to-wordpress/. The code posted doesn't seem to work as is, but after a little fiddling I got the following recipe to work:
<iframe src="http://nbviewer.ipython.org/my_notebook_location" width="100%" height="500" scrolling="yes"></iframe>
However, I don't like the way scrolling works and I'm a little uncomfortable routing my blog through ipython.org.
Raw HTMLplugin to wordpress. You only need to do this once.
ipython nbconvert YOUR_NOTEBOOK.ipynbto get an html file.
URL_OF_NOTEBOOKwith the URL of the html file you uploaded earlier:
After a bunch of searching around I came across a [page] (http://www.bitsofbits.com/wp-content/uploads/2015/01/custom.css) that described how to fix the issue with Safari using JQuery. After some fiddling I magaged to come a standalone fragment of HTML that appears to work correctly on Safari, Chrome and IE (recent versions at least). It's a little more cumersome than the preceding fragment, and does a little extra work on Chrome and IE, but it's a good start. Here's the updated fragment:
That's it, a possibly complete solution for displaying IPython Notebooks in WordPress. Please let me know if it's useful to you. Also please let me know if you have any suggestions for improvements, I suspect I'm doing this the hard way.
Since this is an IPython notebook, I'll throw in the obligatory plot as a demonstration:
%matplotlib inline from matplotlib import pyplot as plt import numpy as np x = np.linspace(0, 10, 1000) plt.plot(x, np.sin(x)) plt.plot(x, np.cos(x))
[<matplotlib.lines.Line2D at 0x105753850>]