J Grif
J Grif

Reputation: 1093

remove nbconvert --to html 'in' and 'out' prompts based on cell metadata

I'd like to remove the red and blue 'In' and 'Out' prompts when running nbconvert --to html, based on cell metadata. With cell metadata such as:

{'cell_tags': {'cutcode_html': true}}

The following sucessfully removes the 'In' prompt:

{% block input_group %}
 {% if cell['metadata'].get('cell_tags',{}).get('cutcode_html','') == True -%}
  <div></div>
 {% else %}
  {{ super() }}
 {% endif %}
{% endblock input_group %}

I'd like to do the equivalent thing for the output prompt.

There has been discussion of how to do this for latex, but I can't figure out how to do it for HTML.

The output_prompt blocks for HTML don't appear to do anything, and whenever I try to make slightly modified versions of the primary templates, they won't load properly.

Upvotes: 4

Views: 1530

Answers (2)

Stefan
Stefan

Reputation: 12370

There is a command line option --no-prompt

nbconvert --to html --no-prompt

Upvotes: 1

Jakob
Jakob

Reputation: 20831

Currently, changing the output prompt is a bit more demanding because if you simply override the block output by extending the full.tpl you have to include a super() call to include the outputs. Unfortunately, the parent block (included by the super call) will add the Out prompt again and will mess up the html.

To get something similar to what you want, I did the following. (Note, I haven't included a complete template here, because the templates are currently changing due to the implementation of the v4 notebook format. Here, I'm using IPython 2.3)

  1. Copy the base.tpl e.g. noprompt.tpl
  2. As this template cannot be used directly, add the code from the full.tpl to noprompt.tpl
  3. change the block input_group as you showed
  4. change the block output to something like

    {% block output %}
    <div class="output_area">
    {%- if cell['metadata'].get('cell_tags',{}).get('cutcode_html','') != True and output.output_type == 'pyout' -%}
    <div class="prompt output_prompt">
    Out[{{ cell.prompt_number }}]:
    {%- else -%}
    <div class="prompt">
    {%- endif -%}
    </div>
    {{ super() }}
    </div>
    {% endblock output %}
    

With this I could convert a notebook with the prompts conditionally removed.

Upvotes: 2

Related Questions