spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
457 stars 130 forks source link

render `ipywidgets.HTML()` #554

Open casperdcl opened 3 years ago

casperdcl commented 3 years ago

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?

mgeier commented 3 years ago

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.

casperdcl commented 3 years ago

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.

mgeier commented 3 years ago

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.