Hide Code when exporting Jupyter notebook to HTML

You can do this with an NBConvert template. Most of the examples out there are for latex/PDF, and won't work with HTML, which uses a different set of templates (and, for some reason, a different extension and slightly different file syntax).

Write the following into a template file called hidecode.tpl:

{%- extends 'full.tpl' -%}

{% block input_group %}
    {%- if cell.metadata.get('nbconvert', {}).get('show_code', False) -%}
        ((( super() )))
    {%- endif -%}
{% endblock input_group %}

Then convert your notebook to HTML with:

jupyter nbconvert --to html --template hidecode YourNotebook.ipynb


as of now (nbconvert version 5.6.0) the easiest solution seems to be to provide the argument --no-input when using the CLI interface of nbconvert:

jupyter nbconvert yourNotebook.ipynb --no-input

it works like magic more info here

Tags:

Python

Jupyter