删除nbconvert - 根据单元格元数据将html'in'和'out'提示删除 [英] remove nbconvert --to html 'in' and 'out' prompts based on cell metadata
问题描述
根据单元格元数据运行 nbconvert - 到html
时,我想删除红色和蓝色的In和Out提示。使用单元格元数据,例如:
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}}
以下成功删除了'In'
提示符:
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.
讨论了如何为 latex ,但我无法弄清楚如何为HTML做这件事。
There has been discussion of how to do this for latex, but I can't figure out how to do it for HTML.
HTML的 output_prompt
块似乎没有做任何事情,每当我尝试做一些略微修改的版本时主模板,它们将无法正确加载。
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.
推荐答案
目前,更改输出提示要求更高,因为如果你只是覆盖块输出
通过扩展 full.tpl ,您必须包含 super()
调用以包含输出。不幸的是,父块(超级调用包含)将再次添加 Out 提示符并将搞乱html。
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.
为了获得类似于你想要的东西,我做了以下工作。 (注意,我这里没有包含完整的模板,因为模板当前正在改变,因为实现了v4笔记本格式。这里,我使用的是IPython 2.3)
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)
- 复制 base.tpl ,例如 noprompt.tpl
- 由于无法直接使用此模板,请将 full.tpl 中的代码添加到 noprompt。 tpl
- 在您展示时更改
块input_group
-
将
块输出
更改为
- Copy the base.tpl e.g. noprompt.tpl
- As this template cannot be used directly, add the code from the full.tpl to noprompt.tpl
- change the
block input_group
as you showed 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.
这篇关于删除nbconvert - 根据单元格元数据将html'in'和'out'提示删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!