treescope.rendering_parts

treescope.rendering_parts#

Parts and builders for Treescope’s intermediate output format.

The functions exposed here can be used to construct a tree of parts that can be rendered to text or to interactive HTML. Node handlers and the __treescope_repr__ method can use them to render custom types.

Note that the internal definition of RenderableTreePart is considered an implementation detail, and is subject to change. To build renderable tree parts, you should instead use the functions exposed here (or higher-level wrappers in treescope.repr_lib).

Classes

RenderableTreePart

Abstract base class for a formatted part of a foldable tree.

RenderableAndLineAnnotations

Groups a main renderable with some line comments.

ExpandState

Enum for expand states.

NodePath

alias of str

Functions

build_full_line_with_annotations(*args)

Concatenates tree parts and appends their line comments at the end.

empty_part()

Returns an empty part.

floating_annotation_with_separate_focus(child)

Wraps a child so that selections outside it don't include it.

fold_condition([collapsed, expanded])

Builds a part that renders differently when collapsed or expanded.

in_outlined_box(child[, css_style])

Wraps a child into an outlined box.

indented_children(children[, ...])

Builds a IndentedChildren instance, supporting annotations and delimiters.

on_separate_lines(children)

Builds a part that renders its children on separate lines.

roundtrip_condition([roundtrip, not_roundtrip])

Builds a part that renders differently in roundtrip mode.

siblings_with_annotations(*args[, ...])

Combines siblings that may have annotations, aggregating separately.

siblings(*args)

Builds a Siblings part from inline arguments.

summarizable_condition([summary, detail])

Builds a part that renders depending on combination of roundtrip/collapsed.

text(text_content)

Builds a one-line text part.

vertical_space(css_height)

Returns a vertical space with the given height in HTML mode.

with_layout_mark(child, mark)

Returns a part that marks its child for layout purposes.

build_copy_button(path)

Builds a copy-path button, if path is provided and not empty.

build_custom_foldable_tree_node(contents[, ...])

Builds a custom foldable tree node with path buttons.

build_foldable_tree_node_from_children(...)

Builds a foldable tree node with path buttons.

build_one_line_tree_node(line[, path, ...])

Builds a single-line tree node with path buttons.

maybe_qualified_type_name(ty)

Formats the name of a type so that it is qualified in roundtrip mode.

abbreviation_color(child)

Returns a wrapped child in a color for non-roundtrippable abbreviations.

comment_color_when_expanded(child)

Returns a wrapped child in a color for comments, but only when expanded.

comment_color(child)

Returns a wrapped child in a color for comments.

custom_text_color(child, css_color)

Returns a wrapped child that renders in a particular CSS color.

deferred_placeholder_style(child)

Returns a wrapped child in italics to indicate a deferred placeholder.

error_color(child)

Returns a wrapped child in red to indicate errors / problems during rendering.

qualified_type_name_style(child)

Returns a wrapped child in a small font to indicate a qualified name.

custom_style(child, css_style)

Returns a wrapped child with a custom CSS style.

build_field_children(node, path, ...[, ...])

Renders a set of fields/attributes into a list of comma-separated children.

render_dataclass_constructor(node)

Renders the constructor for a dataclass, including the open parenthesis.

embedded_iframe(embedded_html, ...[, ...])

Returns a wrapped child in a color for non-roundtrippable abbreviations.