yera.runtime.handlers.segment

Split a streaming markdown buffer into a settled prefix and a live tail.

Symbols

def harvest_refdefs — Extract link reference definitions from committed markdown.
def split_settled — Split a streaming buffer into a committable prefix and a live tail.

harvest_refdefs

harvest_refdefs(
    text: str,
) → list[str]

Extract link reference definitions from committed markdown.

Definitions emit no HTML but bind names used later, so replaying them into each subsequent segment costs nothing and keeps a [foo] in segment 3 resolvable against a definition committed in segment 0.

Parameters

text
type: str

A settled markdown region.

Returns

type: list[str]

The refdef source lines, stripped, in document order.

split_settled

split_settled(
    buffer: str,
) → tuple[str, str]

Split a streaming buffer into a committable prefix and a live tail.

The prefix is the largest region ending at a blank line that renders identically in isolation as it would in the whole document. Blank lines inside fences, display math, lists, or indented code are not split points: a later chunk can still change how the text above them renders.

Deciding a blank line closed a block needs the next line, complete — a partial 2 is not an ordered-list marker but 2. is, so classifying a line still arriving would split a list in two. A buffer whose lookahead is absent or unterminated therefore commits nothing.

Parameters

buffer
type: str

Markdown accumulated so far. May end mid-line.

Returns

type: str

A (settled, live) pair concatenating back to buffer. settled is "" when nothing can be committed yet.