Documentation
¶
Overview ¶
Package mdstream partitions streamed markdown into a stable prefix and a mutable tail. Streaming text into a terminal renderer has a conflict: text committed to scrollback is rendered once and never touched again, but markdown cannot be rendered correctly until its enclosing block is complete (a table cannot be laid out from half its rows; an unclosed fence's end is unknown). The splitter resolves it by advancing a commit boundary only at provably safe points, so the renderer commits the stable prefix exactly once and re-renders only the small mutable tail each frame.
Safe boundaries are structural, not heuristic: the end of a line that closes a code fence, or a blank line outside any fence. Everything after the last safe boundary is tail. This yields the holdback behavior the session needs for free: a streaming table has no blank line inside it, so it stays in the tail (re-rendered whole each frame, laid out correctly once complete), and everything inside an open fence stays in the tail until the fence closes.
The splitter never inspects render output and allocates nothing per write beyond the buffer append: it is a cursor over bytes, cheap enough to run on every streamed chunk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Splitter ¶
type Splitter struct {
// contains filtered or unexported fields
}
Splitter accumulates streamed markdown and tracks the commit boundary. The zero value is ready to use.
func (*Splitter) Close ¶
Close marks the stream complete and returns any remaining uncommitted text: at end of stream every block is as complete as it will ever be, so the whole tail becomes stable.
func (*Splitter) Stable ¶
Stable returns the newly committed text since the last call: the part of the stream that is now provably safe to render and print exactly once.