Reputation: 19235
What is the best way to get an ipython notebook into html format for use in a blog post?
It is easy to turn an ipython notebook into a PDF, but I'd rather publish as an html notebook.
I've found that if I download the notebook as a .ipynb file, then load it onto gist, then look at it with the ipython notebook viewer (nbviewer.ipython.org), THEN grab the html source, I can paste it into a blog post (or just load it as html anywhere) and it looks about right. However, if I use the "print view" option directly from ipython, the source contains a bunch of javascript rather than the processed html, which is not useful since the images and text are not directly included.
The %pastebin
magic is also not particularly helpful for this task, since it pastes the python code and not the ipython notebook formatted code.
EDIT: Note that this is under development; see the comments under the accepted answer.
EDIT May 2 2014: As per Nathaniel's comment, a new answer is needed for ipython 2.0
Upvotes: 37
Views: 15826
Reputation: 933
MyST Markdown's command line tools mystmd
can create websites from multiple notebooks and markdown files, as well as build PDF outputs directly.
Using these tools you can run a whole website / blog from jupyter notebooks rather then exporting html for individual posts.
The myst getting started guide is here: https://mystmd.org/guide/quickstart-myst-websites
Websites can be deployed to/as static HTML, netlify or curvenote and added to CI workflows.
Upvotes: 1
Reputation: 11
You generate the html from cmd, with your Jupyter Notebook open:
As https://stackoverflow.com/a/47773252/15117772 answered a similar question:
Also pass the --execute flag to generate the output cells
jupyter nbconvert --execute --to html notebook.ipynb
jupyter nbconvert --execute --to pdf notebook.ipynb
Upvotes: 1
Reputation: 2233
All the above answers seems outdated. Here is the most modern solution taken from the official nbconvert
docs.
$ jupyter nbconvert --to FORMAT notebook.ipynb
The default output format is html
, for which the --to
argument may be omitted:
$ jupyter nbconvert notebook.ipynb
Upvotes: 8
Reputation: 3721
One step further from the answer above. To create a PDF file,
create a tex file
nbconvert -f latex your_notebook.ipynb
convert tex to pdf :
pdflatex your_notebook.tex
Upvotes: 11
Reputation: 27639
The right way is described in: http://blog.fperez.org/2012/09/blogging-with-ipython-notebook.html. Then you can do nbconvert -f blogger-html your_notebook.ipynb
to get the html code for your post.
Upvotes: 17