Jupyter nbconvert:扩展reveal.js;在标题中添加样式和脚本

Flo*_*loE 5 jupyter-notebook nbconvert

正如标题所示:我想扩展jupyter 的 nbconvert 的显示<style type="text/css"> ... </style>模板,并<script> ... </script></head>.

我目前正在使用 Linux 和 anaconda3 以及jupyter 4.7nbconvert 6.0.7

我创建了一个名为Reveal_extension的文件夹,其中~/anaconda3/share/jupyter/nbconvert/templates/包含以下文件:

  • conf.json
  • 基本.html.j2

conf.json是Reveal模板的conf.json文件的副本,其中"base_template": "reveal",

base.html.j2是一个新文件,内容如下:

{%- extends 'reveal/base.html.j2' -%}

{%- block html_head -%}

{{ super() }}

<style type="text/css">
  CSS-code
</style>

<script>
 javascript-code
</script>


{%- endblock html_head -%} 
Run Code Online (Sandbox Code Playgroud)

当我使用此模板编译jupyter.ipynb笔记本时,我得到了Reveal.js的有效输出,但没有额外的代码。 jupyter nbconvert jupyter.ipynb --to slides --template=reveal_extension

当我在输出jupyter.slides.html文件中手动添加代码时,一切都按预期进行。

我究竟做错了什么?

如何使用模板通过nbconvert在Reveal.js演示文稿中插入附加代码?

Ste*_*EOX 2

我认为您混淆了 Jinja 模板。根据nbconvert docsindex.html.j2是主要入口点。

如果我拿走你的base.html.j2档案并

  1. 将其重命名为index.html.j2
  2. 替换{%- extends 'reveal/base.html.j2' -%}{%- extends 'reveal/index.html.j2' -%}

我在转换后的 HTML 中获取了添加的代码。