wrap_as_treescope_figure#
- penzai.treescope.figures.wrap_as_treescope_figure(value: Any) part_interface.RenderableTreePart[source]#
Converts an arbitrary object to a renderable treescope part if possible.
Behavior depends on the type of
value:If
valueis an instance ofRendersAsRootInIPython, returns it unchanged, since it knows how to render itself.If
valueis a string, returns a rendering of that string.If
valuehas a_repr_html_method (but isn’t an instance ofRendersAsRootInIPython), returns an embedded iframe with the given HTML contents.Otherwise, renders the value using the default treescope renderer, but strips off any top-level comments / copy button annotations.
The typical use is to provide helper constructors for containers to allow rendering lots of different objects in the “obvious” way.
- Parameters:
value – Value to wrap.
- Returns:
A renderable treescope part showing the value.