Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

css - <details></details> HTML5 drop-down character not shown in Jupyter HTML nbconverted files in Firefox

This issue has caused me some headaches. For a jupyter lab workshop, we used <details></details> to provide more information on click.

However, when the notebook was converted to HTML via nbconvert, the drop-down arrows would only show in Chrome, not Firefox.

Have a look at this (Firefox): enter image description here

In Chrome: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is caused by the following Bootstrap element ..

summary {
  display: block;
}

..which is added to the HTML output.

To fix the issue, the following code must be added to the converted HTML:

<style type="text/css">
/* Fix details summary arrow
   not shown in Firefox
   due to bootstrap
   display: block;
 */
summary {
    display: list-item;
}
</style>

It is possible to create a nbconvert template that adds this automatically.

Create the a file called nbconvert.tpl with the following contents:

{% extends 'full.tpl'%}

{# this template will render cells with tags highlight,
highlight_red and hide_code differently #}

{% block header %}
    {{ super() }}
    <style type="text/css">
    /* Fix details summary arrow
       not shown in Firefox
       due to bootstrap
       display: block;
     */
    summary {
        display: list-item;
        outline: none;
    }
    </style>
{% endblock header%}

{% block input_group %}
    {{ super() }}
{% endblock input_group %}

{% block output_group %}
    {{ super() }}
{% endblock output_group %}

And use it when converting jupyter notebooks to HTML files:

jupyter nbconvert --to html 
    --output-dir=. ./notebook.ipynb 
    --template=./nbconvert.tpl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...