ml_switcheroo.core.html¶

HTML/SVG DSL Core Package.

This package defines the intermediate representation for the HTML Visual DSL. This allows converting ASTs into a visual Grid-based explanation format.

Submodules¶

Classes¶

HtmlNode

Abstract base class for all HTML DSL elements.

GridBox

Represents a content box positioned within the CSS Grid.

SvgArrow

Represents an SVG connection line between grid cells.

HtmlDocument

Root container for the generated HTML.

Package Contents¶

class ml_switcheroo.core.html.HtmlNode[source]¶

Abstract base class for all HTML DSL elements.

abstractmethod to_html() → str[source]¶

Render the node and its children to an HTML string.

Returns:

The raw HTML content.

Return type:

str

Raises:

NotImplementedError – If not implemented by subclass.

class ml_switcheroo.core.html.GridBox[source]¶

Bases: HtmlNode

Represents a content box positioned within the CSS Grid.

row: int¶
col: int¶
css_class: str¶
header_text: str¶
code_text: str | None = None¶
body_text: str | None = None¶
arrows: List[SvgArrow] = []¶
z_index: int | None = None¶
to_html() → str[source]¶

Renders the grid cell div, its content, and attached arrows.

class ml_switcheroo.core.html.SvgArrow[source]¶

Bases: HtmlNode

Represents an SVG connection line between grid cells.

x1: int¶
y1: int¶
x2: int¶
y2: int¶
style_class: str¶
marker_end: str¶
parent_style: str¶
to_html() → str[source]¶

Renders the arrow as an absolute SVG element. Adds ‘sw-arrow’ class for scoped styling.

class ml_switcheroo.core.html.HtmlDocument[source]¶

Bases: HtmlNode

Root container for the generated HTML.

model_name: str¶
children: List[GridBox]¶
to_html() → str[source]¶

Renders the complete HTML document.

Notes:

  • Removed ‘visibility:hidden’ from markers block to enable correct rendering in some browsers when injected via innerHTML. Use 0 sizes and pointer-events logic instead.

Returns:

The complete HTML string document.