nbsphinx icon indicating copy to clipboard operation
nbsphinx copied to clipboard

render `ipywidgets.HTML()`

Open casperdcl opened this issue 4 years ago • 3 comments

If a python notebook cell contains e.g. display(ipywidgets.HTML("<span>Hello</span>")), ideally nbsphinx should keep the raw HTML. Is there any other way a python code cell (not markdown cell) can use raw HTML?

casperdcl avatar Apr 09 '21 10:04 casperdcl

What do you mean by "keep the raw HTML"?

When I run the given code, the formatted text "Hello" is displayed, the <span> markup is not visible (but is taken into account by the browser).

When I do the same with nbsphinx, the output is the same.

Is there any other way a python code cell (not markdown cell) can use raw HTML?

from IPython.display import HTML
display(HTML("<span>Hello</span>"))

This produces a very similar result, but it doesn't need the widgets machinery.

mgeier avatar Apr 10 '21 18:04 mgeier

Intriguing... display(IPython.display.HTML("<span>Hello</span>")) works but display(ipywidgets.HTML("<span>Hello</span>")) gets stripped by nbsphinx.

In both cases saving & reopening the notebook works as expected; it just seems that nbsphinx removes ipywidgets upon conversion.

casperdcl avatar Apr 12 '21 17:04 casperdcl

I can't reproduce anything getting stripped by nbsphinx.

Do other Jupyter widgets work with nbsphinx?

You can use this notebook for testing: https://nbsphinx.readthedocs.io/en/0.8.3/code-cells.html#Interactive-Widgets-(HTML-only).

If it doesn't work, you should have a look at https://nbsphinx.readthedocs.io/en/0.8.3/code-cells.html#Troubleshooting.

mgeier avatar Apr 13 '21 10:04 mgeier