extend the markdown jupyter nbconvert template to remove codeblocks but keep markdown output from codeblocks

322 Views Asked by At

I need to extend the nbconvert markdown template to remove code blocks but preserve the output of codeblocks. I'm struggling to find the appropriate documentation for nbconvert. The official documentation is very vague and assumes intimate familiarity with jinja templates.

For example, I have a code block that contains:

from IPython.display import display, Markdown

display(Markdown('# Title\n\n This is text\n\n `this is code`'))

The built-in markdown template produces the following output when run with !jupyter nbconvert --to markdown --template my_template my_notebook.ipynb

\```python
from IPython.display import display, Markdown

display(Markdown('# Title\n\n This is text\n\n `this is code`'))
\```


# Title

 This is text

 `this is code`

I would like the template to ignore the source and only provide the output:

# Title

 This is text

 `this is code`

I've tried adding meta-data to the cell and removing it with this:

metadata

{
 "hide_input": true
}

template directive

{% block data_codecell scoped %}
  {% if cell.metadata.get('hide_input', True) %}
{{ output.data['text/markdown'] }}
  {% endif %}

{% endblock data_codecell %}

That does not appear to work and yields the same results.

I can remove the codeblock and the output entirely by using, but that does not solve the larger problem of preserving the output.

{% block codecell %}
{% endblock codecell %}

Any help or a pointer to example templates or documentation is greatly appreciated. The example templates provided by ipython/jupyter are a bit thin in documentation and there are relatively few examples.

0

There are 0 best solutions below