python: render <svg> via _repr_html_

Work around a recent decision in Jupyter Lab and Notebook to render
<svg> is inline <img>, breaking tooltips or text selection.

(Rerendering all notebooks was painful.)

* NEWS: Mention the change.
* python/spot/__init__.py: Add a _repr_html_ method to all
classes that had a _repr_svg_.  It seems Jupyter will use
_repr_html_ by default.
* python/spot/jupyter.py: SVG replace the _repr_svg_ method
by a _repr_html.
* tests/python/_altscc.ipynb, tests/python/_autparserr.ipynb,
tests/python/_aux.ipynb, tests/python/_mealy.ipynb,
tests/python/_partitioned_relabel.ipynb,
tests/python/_product_susp.ipynb, tests/python/_product_weak.ipynb,
tests/python/_synthesis.ipynb, tests/python/aliases.ipynb,
tests/python/alternation.ipynb, tests/python/atva16-fig2a.ipynb,
tests/python/atva16-fig2b.ipynb, tests/python/automata-io.ipynb,
tests/python/automata.ipynb, tests/python/cav22-figs.ipynb,
tests/python/contains.ipynb, tests/python/decompose.ipynb,
tests/python/formulas.ipynb, tests/python/games.ipynb,
tests/python/gen.ipynb, tests/python/highlighting.ipynb,
tests/python/ltsmin-dve.ipynb, tests/python/ltsmin-pml.ipynb,
tests/python/parity.ipynb, tests/python/product.ipynb,
tests/python/randaut.ipynb, tests/python/satmin.ipynb,
tests/python/stutter-inv.ipynb, tests/python/synthesis.ipynb,
tests/python/testingaut.ipynb, tests/python/twagraph-internals.ipynb,
tests/python/word.ipynb, tests/python/zlktree.ipynb: Update all
notebooks.
This commit is contained in:
Alexandre Duret-Lutz 2024-02-09 15:06:07 +01:00
parent 4cf7503fff
commit 3034e8fcc3
36 changed files with 43249 additions and 8585 deletions

View file

@ -145,6 +145,10 @@ class aig:
print_dot(ostr, self, opt)
return _ostream_to_svg(ostr)
# see spot.jupyter.SVG for why we need _repr_html_ instead of _repr_svg_
def _repr_html_(self):
return self._repr_svg_()
def show(self, opt=None):
from spot.jupyter import SVG
return SVG(self._repr_svg_(opt))
@ -210,6 +214,10 @@ class twa:
print_dot(ostr, self, opt)
return _ostream_to_svg(ostr)
# see spot.jupyter.SVG for why we need _repr_html_ instead of _repr_svg_
def _repr_html_(self):
return self._repr_svg_()
def show(self, opt=None):
"""Display the automaton as SVG, in the IPython/Jupyter notebook"""
if opt is None:
@ -479,6 +487,10 @@ class zielonka_tree:
self.dot(ostr)
return _ostream_to_svg(ostr)
# see spot.jupyter.SVG for why we need _repr_html_ instead of _repr_svg_
def _repr_html_(self):
return self._repr_svg_()
_acdnum = 0
@_extend(acd)