Documentation
¶
Overview ¶
Package model is the intermediate representation office-format frontends produce and the GFM renderer consumes. Only fully resolved content lives here: style cascades, numbering and references are resolved before these values are built, and a Document stays self-contained after its source is gone.
Index ¶
- Constants
- Variables
- func CheckboxText(checked bool) string
- func EmptyBlocks(blocks []Block) bool
- func IsEmpty(inlines []Inline) bool
- func PlainText(inlines []Inline) string
- func ResolveHeaderRows(t Table, declared int) int
- type Anchor
- type Asset
- type AssetID
- type Block
- type Cell
- type Checkbox
- type CodeBlock
- type Document
- type GridBuilder
- type Heading
- type Image
- type ImageSource
- type Inline
- type LimitError
- type LineBreak
- type Link
- type List
- type ListItem
- type MarkerKind
- type Math
- type MathBlock
- type Note
- type NoteKind
- type NoteRef
- type Paragraph
- type Quote
- type Rule
- type Slot
- type SourceKind
- type Style
- type Table
- type TableKind
- type Target
- type TargetKind
- type Text
Constants ¶
const ( MaxExpansion = 4_000_000 MaxGridSlots = 4_000_000 )
Fixed, non-configurable table budgets. MaxExpansion bounds the positions span expansion may claim per table; MaxGridSlots bounds the positions a spreadsheet frontend may materialize for one sheet.
Variables ¶
var Log = slog.New(slog.DiscardHandler)
Log receives what the parsers report about parts they skipped. It is not in the upstream code, which logs to slog's default logger: in kvit-coder that would print over the terminal interface, and setting slog's default also redirects the standard log package. The office package swaps in a logger that collects warnings for the duration of one conversion.
Functions ¶
func CheckboxText ¶
func EmptyBlocks ¶
EmptyBlocks reports whether blocks render nothing; only paragraphs count toward emptiness.
func IsEmpty ¶
IsEmpty reports whether nothing would render visibly: only whitespace, empty-target links, anchors and line breaks. Images, note references and checkboxes always count as content.
func PlainText ¶
PlainText flattens inlines to their text: link text, image alt text and formula source are kept, line breaks become newlines, anchors and note references contribute nothing.
func ResolveHeaderRows ¶
ResolveHeaderRows returns declared (capped at the row count) when the format declared header rows, else 1 when the first row labels the columns and 0 otherwise. The first row is a header when the columns below it are consistently typed and the row itself is not.
Types ¶
type GridBuilder ¶
type GridBuilder struct {
// contains filtered or unexported fields
}
GridBuilder is the sole constructor of table grids. The zero value is ready to use.
func (*GridBuilder) Covered ¶
func (b *GridBuilder) Covered() bool
Covered consumes one explicitly written covered position. It reports false when no span accounts for the position; the stray marker then becomes an empty cell.
func (*GridBuilder) Finish ¶
func (b *GridBuilder) Finish(kind TableKind) Table
func (*GridBuilder) KeepCoveredTail ¶
func (b *GridBuilder) KeepCoveredTail()
KeepCoveredTail keeps trailing rows holding only covered positions: a spreadsheet merge region is real extent even when every covered cell is empty.
func (*GridBuilder) NextRow ¶
func (b *GridBuilder) NextRow()
NextRow starts a row with room for as many slots as the previous one.
func (*GridBuilder) Place ¶
func (b *GridBuilder) Place(cell Cell) error
Place puts cell at the next free position of the current row. Positions its spans claim become pending: an explicit covered marker consumes one through Covered, and omitted ones materialize as later cells are placed. Spans overlapping earlier claims are clamped. The whole span area is charged against MaxExpansion before any expansion.
type Heading ¶
Heading levels are the source's outline depth, 1-based and unclamped. Anchor is the id the document targets this heading by, "" when none.
type Image ¶
type Image struct {
Alt string
Source ImageSource
}
type ImageSource ¶
type ImageSource struct {
Kind SourceKind
URL string
Asset AssetID
}
type LimitError ¶
func (*LimitError) Error ¶
func (e *LimitError) Error() string
type List ¶
type List struct {
Marker MarkerKind
Start int
Items []ListItem
}
List is fully resolved: frontends split runs wherever the list instance or marker kind changes, and Start is the source's own ordinal for the first item.
type ListItem ¶
ListItem is one list entry. Label overrides the level marker with literal source number text when marker kind and position cannot reproduce it (composite labels such as "1-a)"); "" means none.
type MarkerKind ¶
type MarkerKind int
const ( Bullet MarkerKind = iota Decimal LowerAlpha UpperAlpha LowerRoman UpperRoman )
func (MarkerKind) Label ¶
func (k MarkerKind) Label(n int) string
Label is the marker text for 1-based ordinal n without trailing space: "3.", "c.", "iv.", or "-" for bullets.
func (MarkerKind) Ordered ¶
func (k MarkerKind) Ordered() bool
func (MarkerKind) Ordinal ¶
func (k MarkerKind) Ordinal(n int) string
type MathBlock ¶
type MathBlock string
MathBlock is a displayed formula as LaTeX without delimiters.
type Slot ¶
Slot is one grid position: an origin holding the cell, or a position covered by the span of the origin at (OriginRow, OriginCol).
type Table ¶
Table is a canonical grid: every logical position appears exactly once, content and spans live only on origins, and each position a span claims holds a covered slot pointing back at its origin. Grids are built only by GridBuilder or TableFromRows. Rows may be ragged.
func TableFromRows ¶
TableFromRows builds a span-less table; any spans on the cells are ignored.
func (Table) IsSingleCell ¶
type Target ¶
type Target struct {
Kind TargetKind
Ref string
}
Target is an absolute URL, a scheme-less relative reference kept as written, or a document-scoped anchor id (a heading anchor or Anchor node).
type TargetKind ¶
type TargetKind int
const ( TargetExternal TargetKind = iota TargetRelative TargetAnchor )