如何将ipynb转换为html,md,pdf等格式

html-css053

如何将ipynb转换为html,md,pdf等格式,第1张

ipynb转为html格式

在Ubuntu命令行输入:

jupyter nbconvert --to html notebook.ipynb1

另外,jupyter提供了一些命令,可以对生成的html格式进行配置:

jupyter nbconvert --to html --template full notebook.ipynb1

这是默认配置,提供完整的静态html格式,交互性更强。

jupyter nbconvert --to html --template basic notebook.ipynb

markdown文件用浏览器直接另存即可转换成html。

转换为PDF,则

1、如果你的md文件使用chrome预览,就比较简单了。 点打印,目标,选本地另存为pdf,即可。

2、如果你的浏览器有虚拟的PDF打印机的,请你PDF虚拟打印机打印你要输出的内容,即可得到你要的PDF文档。

3、如果用其它浏览器,没有虚拟的PDF打印机的,请你安装Adobe Acrobat XI Pro软件,在WORD中用Adobe PDF打印机打印你要输出的内容,即可得到你要的PDF文档。

markdown虽然写起来方便, 但是要预览的话还要用ReText打开, 而且ReText好像是Qt程序, 打开文件时不如别的编辑器那么流畅. 所以想找一个可以把markdown文件变成html格式的工具.

我甚至搜了很久"markdown2html"(github上居然可以搜到好几个项目...) 而没有注意到, 在终端输入"html2markdown"时显示的警告:

$ html2markdown

程序“html2markdown”尚未安装。 您可以使用以下命令安装:

sudo apt-get install pandoc

后来安装了pandoc(sudo apt-get install pandoc), 其实只要看看帮助就知道咋用了:

$ pandoc -h

pandoc [OPTIONS] [FILES]

Input formats: native, markdown, markdown+lhs, rst, rst+lhs, html, latex, latex+lhs

Output formats: native, html, html+lhs, s5, docbook, opendocument, odt, latex, latex+lhs, context, texinfo, man, markdown, markdown+lhs, plain, rst, rst+lhs, mediawiki, rtf

Options:

-f FORMAT, -r FORMAT --from=FORMAT, --read=FORMAT

-t FORMAT, -w FORMAT --to=FORMAT, --write=FORMAT

-s --standalone

-o FILENAME --output=FILENAME

-p --preserve-tabs

--tab-stop=TABSTOP

--strict

--reference-links

-R --parse-raw

-S --smart

-m[URL] --latexmathml[=URL], --asciimathml[=URL]

--mathml[=URL]

--mimetex[=URL]

--jsmath[=URL]

--gladtex

-i --incremental

--xetex

-N --number-sections

--no-wrap

--sanitize-html

--email-obfuscation=none|javascript|references

--id-prefix=STRING

--indented-code-classes=STRING

--toc, --table-of-contents

--base-header-level=LEVEL

--template=FILENAME

-V FILENAME --variable=FILENAME

-c URL --css=URL

-H FILENAME --include-in-header=FILENAME

-B FILENAME --include-before-body=FILENAME

-A FILENAME --include-after-body=FILENAME

-C FILENAME --custom-header=FILENAME

-T STRING --title-prefix=STRING

--reference-odt=FILENAME

-D FORMAT --print-default-template=FORMAT

--data-dir=DIRECTORY

--dump-args

--ignore-args

-v --version

-h --help

真是more than I've expected! markdown/rst/html/latex之间可以互转!

使用pandoc命令就可以在随便转换了, 示例, 把demo.md输出成demo.html:

$pandoc -f markdown -t html -o demo.html demo.md

或者直接:

$pandoc -f markdown -t html -o demo.html demo.md

我觉得这个实在是很有用的一条命令~