如何将IPython笔记本导出为HTML以用于博客帖子? [英] How to export an IPython notebook to HTML for a blog post?

查看:79
本文介绍了如何将IPython笔记本导出为HTML以用于博客帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将ipython笔记本用于html格式以便在博客文章中使用的最佳方法是什么?

What is the best way to get an ipython notebook into html format for use in a blog post?

很容易将ipython笔记本变成PDF,但我宁愿发布为html笔记本。

It is easy to turn an ipython notebook into a PDF, but I'd rather publish as an html notebook.

我发现如果我将笔记本下载为.ipynb文件,然后将其加载到gist上,然后再看看使用ipython notebook viewer(nbviewer.ipython.org),然后获取html源代码,我可以将其粘贴到博客文章中(或者只是将其作为html加载到任何地方),它看起来是正确的。但是,如果我直接使用ipython中的打印视图选项,则源代码包含一堆javascript而不是处理过的html,由于图像和文本不是直接包含在内,因此无效。

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.

%pastebin magic对此任务也没有特别的帮助,因为它粘贴了python代码而不是ipython笔记本格式的代码。

The %pastebin magic is also not particularly helpful for this task, since it pastes the python code and not the ipython notebook formatted code.

编辑:请注意,这正在开发中;请参阅接受答案下的评论。

Note that this is under development; see the comments under the accepted answer.

编辑2014年5月2日:根据纳撒尼尔的评论,ipython 2.0需要一个新答案

EDIT May 2 2014: As per Nathaniel's comment, a new answer is needed for ipython 2.0

推荐答案

正确的方法描述于: http://blog.fperez.org/2012/09/blogging-with-ipython-notebook.html 。然后你可以 nbconvert -f blogger -html your_notebook.ipynb 来获取帖子的html代码。

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.

这篇关于如何将IPython笔记本导出为HTML以用于博客帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆