把Markdown轉成JupyterNotebook,一般情況下很少用到。偶爾要用時,又一時想不起鏈接在哪。所以這裏記錄一下。
之所以附帶上《動手學深度學習》這本書(http://zh.d2l.ai/index.html),是因爲裏面的教程都是markdown寫的,可以做爲例子練練手,很好地轉換成JupyterNotebook格式,爲此,李沐還專門改寫了一個對中文支持更好的版本notedown,
https://github.com/mli/notedown
這個版本的原版本是
https://github.com/aaren/notedown
下面簡單介紹一下使用方法(假設你已經安裝好了JupyterNotebook)。
用Jupyter記事本讀寫GitHub源文件
根據http://zh.gluon.ai/chapter_appendix/jupyter.html描述,下面安裝notedown插件,運行Jupyter記事本並加載插件。
pip install https://github.com/mli/notedown/tarball/master
jupyter notebook --NotebookApp.contents_manager_class='notedown.NotedownContentsManager'
如果想每次運行Jupyter記事本時默認開啓notedown插件,可以參考下面的步驟。
首先,執行下面的命令生成Jupyter記事本配置文件(如果已經生成,可以跳過):
jupyter notebook --generate-config
然後,將下面這一行加入到Jupyter記事本配置文件(一般在用戶主目錄下的隱藏文件夾.jupyter
中的jupyter_notebook_config.py
)的末尾:
c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'
之後,只需要運行jupyter notebook
命令即可默認開啓notedown插件。
用notedown把markdown轉換成JupyterNotebook
在命令窗口下,輸入以下簡單命令即可,
notedown input.md > output.ipynb
用notedown把JupyterNotebook轉成markdown
當然,把Jupyter轉成markdown也很簡單,參考github上aaren的說明原文貼在下面
Convert a notebook into markdown, stripping all outputs:
notedown input.ipynb --to markdown --strip > output.md
Convert a notebook into markdown, with output JSON intact:
notedown input.ipynb --to markdown > output_with_outputs.md
Strip the output cells from markdown:
notedown with_output_cells.md --to markdown --strip > no_output_cells.md