4

As the title suggests: I'd like to extend the reveal template of jupyter's nbconvert and add some custom <style type="text/css"> ... </style> and <script> ... </script> blocks right before the end of the </head>.

I'm currently using Linux and anaconda3 with jupyter 4.7 and nbconvert 6.0.7 .

I created a folder called reveal_extension in ~/anaconda3/share/jupyter/nbconvert/templates/ with the files:

  • conf.json
  • base.html.j2

conf.json is a copy of the conf.json file of the reveal template, with "base_template": "reveal",

base.html.j2 is a new file with the following content:

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

{%- block html_head -%}

{{ super() }}

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

<script>
 javascript-code
</script>


{%- endblock html_head -%} 

When I compile my jupyter.ipynb notebook with this template, I get a valid output with reveal.js but without my additional code. jupyter nbconvert jupyter.ipynb --to slides --template=reveal_extension

When I manually add the code in the output jupyter.slides.html file, everything works as expected.

What am I doing wrong?

How can I insert additional code in the reveal.js presentation with nbconvert using a template?

FloE
  • 1,166
  • 1
  • 10
  • 19

1 Answers1

2

I think that you mixed up the Jinja templates. According to the nbconvert docs, index.html.j2 is the main entry point.

If I take approximately your base.html.j2 file and

  1. rename it to index.html.j2
  2. replace {%- extends 'reveal/base.html.j2' -%} by {%- extends 'reveal/index.html.j2' -%}

I get the added code in the converted HTML.

Stefan_EOX
  • 1,279
  • 1
  • 16
  • 35