httk.serve.web.widgets.extraction

Renderer-aware extraction of literal-only widget(...) invocations.

Functions

parse_widget_invocation(text, *, source_path, line, column)

Parse one literal-only widget invocation without evaluating it.

placement_for(text, *, source_path, line, column, index)

Create a stable renderer placement for one widget invocation.

markdown_source(source, source_path, *[, line_offset])

Replace standalone Markdown widget paragraphs while excluding code blocks.

html_source(source, source_path)

Extract complete HTML widget blocks while skipping code-like tags.

Module Contents

httk.serve.web.widgets.extraction.parse_widget_invocation(text, *, source_path, line, column)[source]

Parse one literal-only widget invocation without evaluating it.

Parameters:
  • text (str) – Complete widget invocation text.

  • source_path (pathlib.Path) – Source file containing the invocation.

  • line (int) – One-based source line.

  • column (int) – One-based source column.

Returns:

Widget name and validated literal properties.

Raises:
Return type:

tuple[str, dict[str, object]]

httk.serve.web.widgets.extraction.placement_for(text, *, source_path, line, column, index)[source]

Create a stable renderer placement for one widget invocation.

Parameters:
  • text (str) – Complete widget invocation text.

  • source_path (pathlib.Path) – Source file containing the invocation.

  • line (int) – One-based source line.

  • column (int) – One-based source column.

  • index (int) – Zero-based placement index in the source.

Returns:

Parsed widget placement with a deterministic placeholder.

Return type:

httk.serve.web.renderers.base.WidgetPlacement

httk.serve.web.widgets.extraction.markdown_source(source, source_path, *, line_offset=0)[source]

Replace standalone Markdown widget paragraphs while excluding code blocks.

Parameters:
  • source (str) – Markdown source text.

  • source_path (pathlib.Path) – Source file containing the text.

  • line_offset (int) – Number of lines preceding the supplied source.

Returns:

Source with placeholders and the extracted placements.

Return type:

tuple[str, tuple[httk.serve.web.renderers.base.WidgetPlacement, Ellipsis]]

httk.serve.web.widgets.extraction.html_source(source, source_path)[source]

Extract complete HTML widget blocks while skipping code-like tags.

Parameters:
  • source (str) – HTML source text.

  • source_path (pathlib.Path) – Source file containing the text.

Returns:

Source with placeholders and the extracted placements.

Return type:

tuple[str, tuple[httk.serve.web.renderers.base.WidgetPlacement, Ellipsis]]