Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render renders a document into a string with the given column limit. indent is the initial indentation for any broken lines.
func RenderAt ¶
RenderAt renders a document as if it started at startCol columns into the current line (used when replacing a sub-span of a line rather than the whole line).
indent is the indentation for broken lines at the current nesting level (it should be a literal prefix written after newline, not a column count).
Types ¶
type Align ¶
type Align struct {
Doc Doc
}
Align renders its child with the indentation set to the current column (spaces) for any broken lines within its child.
This is primarily used for alignment-based indentation (e.g. after an opening paren). It intentionally uses spaces to precisely match the measured column width, even when the surrounding code uses tabs.
type Doc ¶
type Doc interface {
// contains filtered or unexported methods
}
Doc is a tiny pretty-printing document tree.
This is intentionally minimal: it's a foundation for gradually migrating string-based heuristic formatters to a single stable layout engine.
The model is: - Text emits literal text. - Line is either a space (flat mode) or a newline+indent (break mode). - Group tries to render flat, otherwise renders broken. - Concat concatenates docs. - Nest increases indentation for any broken lines within its child. - IfBreak chooses between 2 docs based on mode. - Align indents broken lines to the current column.
type ForceBreak ¶
type ForceBreak struct{}
ForceBreak is a doc node that prevents its containing Group from rendering in flat mode. It is a minimal "break parent" building block: by making fitsAt fail, any Group that contains a ForceBreak will choose break mode.
This is intentionally low-level; higher-level actions can insert ForceBreak in cases where partial flattening would be undesirable (e.g. call-arg lists where a nested arg requires line breaks).
type IfBreak ¶
IfBreak selects between two docs based on the rendering mode. In flat mode, Flat is rendered; in break mode, Broken is rendered.
type IndentByCols ¶
IndentByCols increases indentation by a fixed number of columns (spaces) for any broken lines within its child.
This is useful for aligning continuation blocks relative to indentation without needing to know the exact whitespace prefix string.