document

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder() *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(input []byte) *model.Document

Decode parses a block of text and builds a model.Document.

A model.Document can hold any sequence of alternating model.Text and model.Table objects.

Tables (rulers and data rows) are built from consecutive table-like lines of text. If a line cannot be parsed as a row or a ruler, the table is 'closed' and a new table will be created if necessary.

Any text which cannot be parsed is retained verbatim.

Thus it is always possible to parse a document (out of memory issues aside)

func (*Decoder) SetPrefixPattern

func (dec *Decoder) SetPrefixPattern(prefix model.Nullable[string])

SetPrefixPattern specifies which pattern should be used for detecting tables within e.g. code comments

See encoding/prefix/Matcher

type Encoder

type Encoder struct {
	LocaleTag string // e.g. en_US, de_DE, ...
	Prefix    model.Nullable[string]
}

Encoder encodes a document as a byte slice, for printing

Invariants:

  • optional prefix for all tables
  • >= 0 items
  • each item
  • 0 or 1 unformated block of text
  • 0 or 1 table

func (*Encoder) Encode

func (enc *Encoder) Encode(doc *model.Document) []byte

func (*Encoder) SetPrefix

func (enc *Encoder) SetPrefix(prefix model.Nullable[string])

SetPrefix sets an explicit prefix to use on all tables

This is NOT typically desirable behaviour!

Typically, each table should retain the prefix of its first row (data or ruler)

To override this behaviour, specify a prefix which begins or ends with one or more whitespace characters.

-p xyz only used to match existing prefixes while decoding (ignore for encoder) -p " xyz " (prefix with leading or trailing spaces) explicitly set prefix for encoding

TODO: 2025-03-08 this is dodgy behaviour (side-effect based) and should either be removed or replaced by a more explicit operation

Jump to

Keyboard shortcuts

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