Help us shape the future of Go! Take the 2026 Go Developer Survey

markup

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package markup is the Markdown every editable deliverable is written in: front matter, blocks, the ::: directives, ==fields== the buyer replaces, and the language's typography, so authors type plain text and documents and decks read the same source the same way.

Index

Constants

View Source
const (
	Para      = "p"
	Heading   = "h" // Level 1-3
	Title     = "title"
	Subtitle  = "subtitle"
	List      = "list"
	TableKind = "table"
	ImageKind = "image"
	PageBreak = "break"
	Ornament  = "ornament"
	Box       = "box"
	Columns   = "columns"
	Form      = "form"
	Signature = "signature"
	Notes     = "notes" // a slide's speaker notes
)

Block kinds.

Variables

View Source
var (
	FieldMark = regexp.MustCompile(`==([^=\n]+)==`) // a field in plain text

)

Functions

func Aligns

func Aligns(t *Table) []string

Aligns resolves a table's column alignments: as written, or numbers right.

func HTML

func HTML(b *strings.Builder, ins []Inline)

HTML writes runs as HTML: bold, italic, fields and links.

func Keys

func Keys(settings map[string]Setting) []string

Keys are the settings' keys in the order of their lines.

func Lines

func Lines(src []byte) []string

Lines splits a source file into lines. A UTF-8 byte order mark, which some editors write, is dropped, so front matter and a first heading still start the file.

func Numeric

func Numeric(t *Table, col int) bool

Numeric reports whether a column holds figures in every filled body cell.

func Parse

func Parse(lines []string, offset int, o Options) ([]Block, []Problem)

Parse reads the body of a source, lines starting at source line offset+1, into blocks.

func Plain

func Plain(in []Inline) string

Plain is the text of runs.

func Tie

func Tie(s string) string

Tie keeps together what must not break across lines.

func Widths

func Widths(t *Table) []float64

Widths shares a table's width by its columns' longest words and lines: short figures get narrow columns, prose wide ones.

Types

type Block

type Block struct {
	Kind     string
	Level    int // heading level
	Line     int // source line
	Center   bool
	Inlines  []Inline
	Items    []Item // list
	Ordered  bool
	Table    *Table
	Image    *Figure
	Children []Block   // box
	Cols     [][]Block // columns
	Widths   []float64 // column shares
	Fields   []Field   // form, signature
}

Block is one block of a document.

type Field

type Field struct {
	Label []Inline
	Value []Inline
}

Field is a form row or a signature line.

type Figure

type Figure struct {
	Src, Alt string
	Width    float64 // mm; 0 fits the text width
	Share    float64 // of the text width when given in %
}

Figure is an inline picture.

type Inline

type Inline struct {
	Text         string
	Bold, Italic bool
	Fill         bool   // a field the buyer replaces: ==…==, highlighted
	Link         string // a hyperlink target
	Break        bool   // a line break before the text
}

Inline is a run of text with one look.

func Fields

func Fields(in []Inline) []Inline

Fields splits ==…== out of the runs as fields the buyer replaces.

type Issue

type Issue struct{ Message, Hint string }

Issue is a problem with a piece of sample text and how to fix it.

func Sample

func Sample(s, marks string) []Issue

Sample is what reads wrong in sample text a buyer judges a template by: filler, shouting capitals, emoji. marks are the symbols lfm itself sets.

type Item

type Item struct {
	Level   int // 0-2
	Check   bool
	Checked bool
	Inlines []Inline
}

Item is one list item.

type Options

type Options struct {
	Lang       string
	Directives []string // the ::: directives allowed, such as title, columns, notes
	Slides     bool     // a line --- starts the next slide
}

Options are what a deliverable's sources may hold.

type Problem

type Problem struct {
	Line          int
	Message, Hint string
}

Problem is a defect in a source file, by line.

func FrontMatter

func FrontMatter(lines []string) (map[string]Setting, int, []Problem)

FrontMatter reads the settings between the leading --- lines by their lowercase keys, and where the body starts.

type Setting

type Setting struct {
	Value string
	Line  int
}

Setting is one front matter line.

type Table

type Table struct {
	Align []string // left, center, right or "" (numbers right, text left) per column
	Head  [][]Inline
	Rows  [][][]Inline
}

Table is a table with a header row.

Jump to

Keyboard shortcuts

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