model

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

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 CheckboxText(checked bool) string

func EmptyBlocks

func EmptyBlocks(blocks []Block) bool

EmptyBlocks reports whether blocks render nothing; only paragraphs count toward emptiness.

func IsEmpty

func IsEmpty(inlines []Inline) bool

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

func PlainText(inlines []Inline) string

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

func ResolveHeaderRows(t Table, declared int) int

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 Anchor

type Anchor string

type Asset

type Asset struct {
	ID         AssetID
	MediaType  string
	OriginPart string
	Bytes      []byte
}

type AssetID

type AssetID int

type Block

type Block interface {
	// contains filtered or unexported methods
}

type Cell

type Cell struct {
	Blocks  []Block
	ColSpan int
	RowSpan int
}

Cell spans below 1 count as 1.

func (Cell) IsEmpty

func (c Cell) IsEmpty() bool

IsEmpty reports whether the cell renders nothing.

type Checkbox

type Checkbox bool

type CodeBlock

type CodeBlock struct {
	Lang string
	Text string
}

type Document

type Document struct {
	Blocks []Block
	Notes  []Note
	Assets []Asset
}

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

type Heading struct {
	Level   int
	Anchor  string
	Content []Inline
}

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 Inline

type Inline interface {
	// contains filtered or unexported methods
}

type LimitError

type LimitError struct {
	Limit  string
	Detail string
}

func (*LimitError) Error

func (e *LimitError) Error() string

type LineBreak

type LineBreak struct{}
type Link struct {
	Content []Inline
	Target  Target
}

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

type ListItem struct {
	Blocks []Block
	Label  string
}

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 Math

type Math string

Math is an inline formula as LaTeX without delimiters.

type MathBlock

type MathBlock string

MathBlock is a displayed formula as LaTeX without delimiters.

type Note

type Note struct {
	ID     string
	Kind   NoteKind
	Blocks []Block
}

type NoteKind

type NoteKind int
const (
	Footnote NoteKind = iota
	Endnote
)

type NoteRef

type NoteRef string

type Paragraph

type Paragraph []Inline

type Quote

type Quote []Block

type Rule

type Rule struct{}

type Slot

type Slot struct {
	Covered   bool
	OriginRow int
	OriginCol int
	Cell      Cell
}

Slot is one grid position: an origin holding the cell, or a position covered by the span of the origin at (OriginRow, OriginCol).

type SourceKind

type SourceKind int
const (
	SourceUnavailable SourceKind = iota
	SourceExternal
	SourceAsset
)

type Style

type Style struct {
	Bold   bool
	Italic bool
	Strike bool
	Code   bool
}

type Table

type Table struct {
	HeaderRows int
	Kind       TableKind
	// contains filtered or unexported fields
}

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

func TableFromRows(rows [][]Cell, headerRows int, kind TableKind) Table

TableFromRows builds a span-less table; any spans on the cells are ignored.

func (Table) Grid

func (t Table) Grid() [][]Slot

func (Table) IsSingleCell

func (t Table) IsSingleCell() bool

type TableKind

type TableKind int
const (
	DataTable TableKind = iota
	LayoutTable
)

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
)

type Text

type Text struct {
	Text  string
	Style Style
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL