middleware.streaming_html

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

Inject HTML snippets into streamedtext/html bodies before </body>.

BufferedResponse bodies are handled by HTMLInject. Streaming StreamingResponse chunks need a bounded buffer so </body>split across chunks is detected…

Inject HTML snippets into streamedtext/html bodies before </body>.

BufferedResponse bodies are handled by HTMLInject. Streaming StreamingResponse chunks need a bounded buffer so </body>split across chunks is detected without materializing the entire body.

middleware.streaming_html

Name Type Default Description
type —
qualified_name —
element_type —
description —
source_file —
line_number —
is_autodoc —
autodoc_element —
_autodoc_template —
_autodoc_url_path —
_autodoc_page_type —
title —
doc_content_hash —

Symbols on this page

_chunks_to_async
function async
async def _chunks_to_async(chunks: Iterator[str] | AsyncIterator[str]) -> AsyncIterator[str]

Normalize sync or async chunk iterators to async iteration.

Parameters

Name Type Default Description
chunks Iterator[str] | AsyncIterator[str] —
async_stream_inject_before_body
function async
async def async_stream_inject_before_body(chunks: Iterator[str] | AsyncIterator[str], *, snippet: str, before: str = '</body>', dedup_marker: str | None = None, dedup_script_chirp: str | None = None, full_page_only: bool = True) -> AsyncIterator[str]

Yield HTML chunks, inserting snippet before the first before delimiter.

If dedup_marker is set and appears before the first before, the stream is passed through unchanged (no double injection).

If dedup_script_chirp is set, dedup requires a<script data-chirp="…"> tag with that value (avoids false positives from page content mentioning the marker string).

If before never appears and full_page_only is True, the buffered tail is yielded as-is (same asHTMLInject when </body>is absent).

Handles before split across chunk boundaries via a bounded buffer.

Parameters

Name Type Default Description
chunks Iterator[str] | AsyncIterator[str] —
snippet str —
before str '</body>'
dedup_marker str | None None
dedup_script_chirp str | None None
full_page_only bool True

View source · /home/runner/work/chirp/chirp/site/../src/chirp/middleware/streaming_html.py:1