render_selection_to_foldable_representation

render_selection_to_foldable_representation#

penzai.treescope.selection_rendering.render_selection_to_foldable_representation(selection: selectors.Selection, visible_selection: bool = True, ignore_exceptions: bool = False) part_interface.RenderableTreePart[source]#

Renders a top-level selection object to its foldable representation.

This function produces a rendering of either the selection itself, or its selected value. However, instead of directly outputting the attributes of the selection, we draw the selected regions as highlighted boxes around selected subtrees.

The output is still a round-trippable “repr”-like output. When visible_selection is True, copying it will reproduce the original selection. When visible_selection is False, copying it will reproduce the selected value.

Parameters:
  • selection – A selection to render.

  • visible_selection – Whether to render the selection itself rather than the selected value. If True, renders code to build the selection itself, and highlights selected nodes in blue. If False, renders the value but expands the selected nodes.

  • ignore_exceptions – Whether to catch errors during rendering of subtrees and show a fallback for those subtrees, instead of failing the entire renderer. Best used in contexts where render_selection_to_foldable_representation is not being called directly, e.g. when registering this as a default pretty-printer.

Returns:

A representation of the selection, expanded accordingly.