sphinx_gallery.notebook#
用於 Jupyter 筆記本的解析器。
保存 Jupyter 筆記本資訊的類別
函式#
- sphinx_gallery.notebook.add_code_cell(work_notebook, code)[原始碼]#
在筆記本中加入程式碼儲存格。
- 參數:
code (str) – 儲存格內容
- sphinx_gallery.notebook.add_markdown_cell(work_notebook, markdown)[原始碼]#
在筆記本中加入 Markdown 儲存格。
- 參數:
markdown (str) – Markdown 儲存格內容。
- sphinx_gallery.notebook.convert_code_to_md(text)[原始碼]#
重寫程式碼區塊,以使用 Markdown 偏好的反引號標記法。
反引號標記法保留語法高亮。
- 參數:
text (str) – 大部分已轉換為 Markdown 文字的字串。可能包含零個、一個或多個程式碼區塊(以程式碼區塊格式)。
- sphinx_gallery.notebook.fill_notebook(work_notebook, script_blocks, gallery_conf, target_dir)[原始碼]#
寫入 Jupyter 筆記本儲存格。
如果可用,則使用 pypandoc 將 reST 轉換為 Markdown。
- 參數:
script_blocks (list) – 每個列表元素都應該是一個 (label, content, lineno) 的元組。
- sphinx_gallery.notebook.generate_image_src(image_path, gallery_conf, target_dir)[原始碼]#
根據「notebook_images」設定,修改筆記本的圖片路徑。
URL 不變。「notebook_images」設定為字串時,將作為圖片路徑的前綴,相對於「src_dir」。如果「notebook_images」是 True,則圖片會嵌入為 URI。如果「notebook_images」是 False,則會加上「file://」。
- sphinx_gallery.notebook.jupyter_notebook(script_blocks, gallery_conf, target_dir)[原始碼]#
逐個儲存格產生 Jupyter 筆記本檔案。
- 參數:
script_blocks (list) – 腳本執行儲存格。
gallery_conf (dict) – sphinx-gallery 設定字典。
target_dir (str) – 筆記本預定的路徑。用於可能需要相對路徑的地方。
- sphinx_gallery.notebook.promote_jupyter_cell_magic(work_notebook, markdown)[原始碼]#
將文字區塊中的 Jupyter 儲存格魔法升級為筆記本中的程式碼區塊。
解析 Markdown 文字區塊,尋找以 Jupyter 儲存格魔法(例如 %%bash)開頭的程式碼區塊。每當找到一個時,會將其之前的文字和程式碼(作為可執行的程式碼區塊)加入到 work_notebook 中。任何剩餘的文字都會被傳回。
- 參數:
markdown (str) – Markdown 儲存格內容。
- sphinx_gallery.notebook.python_to_jupyter_cli(args=None, namespace=None, sphinx_gallery_conf=None)[原始碼]#
將 Jupyter 筆記本渲染器暴露給命令列。
接受與 ArgumentParser.parse_args 相同的參數。sphinx_gallery_conf 的作用與 conf.py 中相同。
- sphinx_gallery.notebook.rst2md(text, gallery_conf, target_dir, heading_levels)[原始碼]#
將 docstring 和文字區塊中的 reST 轉換為 Jupyter 筆記本的 Markdown。
- 參數:
text (str) – 要轉換為 MD 的 reST 輸入
gallery_conf (dict) – sphinx-gallery 設定字典。
target_dir (str) – 筆記本預定的路徑。用於可能需要相對路徑的地方。
heading_levels (dict) – 標題樣式
(over_char, under_char)
對應到標題層級的映射。請注意,當只有底線時,over_char
為 None。