我在 docker 容器中运行 Jupyter。我在 Jupyter 中应用了不同的主题。我可以打开我的笔记本并查看新主题。我可以将它下载为 HTML 并且主题仍然存在。
准备好笔记本后,我使用 papermill 运行它的多个副本,然后运行以下代码片段,使用 nbconvert 将笔记本转换为 HTML。我的问题是它没有选择当前主题,而是选择了默认主题。
# Disable the ExtractOutput preprocessor. This prevents images embedded on the notebook (ie: plots) from being externally linked
config = {"ExtractOutputPreprocessor": {"enabled": False}}
# Find the HTML (with TOC) exporter
HTMLTOCExporter = nbconvert.exporters.exporter_locator.get_exporter(
"html_toc"
)
exporter = HTMLTOCExporter(config)
# Add a preprocessor to the exporter to remove the notebook cells with the tag 'remove_cell'
cell_remover = TagRemovePreprocessor(
remove_cell_tags={"remove_cell"}, remove_input_tags={"remove_input"}
)
exporter.register_preprocessor(cell_remover, True)
# Generate HTML and write it to a file
html, resources = exporter.from_filename(notebook_path)
with open(html_tmp_path, "w") as f:
f.write(html)
我查看了文档,它说默认模板应该类似于 Jupyter Interactive 视图,但导出的 HTML 看起来与 jupyter 不同。https://nbconvert.readthedocs.io/en/latest/usage.html#html