markdown

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package markdown turns markdown written by the model into a neutral fragment: headings, paragraphs, list items, code lines and tables with styled inline runs. It refuses, loudly, anything the Docs API cannot express so nothing degrades silently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Kind    BlockKind
	Level   int // heading level 1-6
	Ordered bool
	Nesting int // list nesting, 0-based
	ListID  int // groups consecutive items of one list
	Inlines []Inline
	Lines   []string // code block lines
	Table   *Table
	Line    int // 1-based source line, for errors
}

Block is one paragraph-level element.

func (*Block) Text

func (b *Block) Text() string

Text returns the block's plain text.

type BlockKind

type BlockKind string

BlockKind is a fragment block type.

const (
	KindParagraph BlockKind = "paragraph"
	KindHeading   BlockKind = "heading"
	KindListItem  BlockKind = "list_item"
	KindCode      BlockKind = "code"
	KindTable     BlockKind = "table"
)

Block kinds.

type Fragment

type Fragment struct {
	Blocks []*Block
}

Fragment is parsed markdown.

func Parse

func Parse(src string) (*Fragment, error)

Parse converts markdown to a fragment. Plain text is valid markdown, so any string parses; only constructs without a Docs equivalent fail.

func Plain

func Plain(text string) *Fragment

Plain wraps verbatim text as a fragment: one paragraph per line, no formatting.

func (*Fragment) PlainText

func (f *Fragment) PlainText() string

PlainText joins the blocks' text with newlines.

func (*Fragment) SingleParagraph

func (f *Fragment) SingleParagraph() (string, bool)

SingleParagraph reports whether the fragment is one plain paragraph with no formatting, and returns its text. Such fragments can be applied as a minimal diff.

type Inline

type Inline struct {
	Text   string
	Bold   bool
	Italic bool
	Strike bool
	Code   bool
	Link   string
}

Inline is a run of text with one formatting.

func (Inline) Style

func (i Inline) Style() Inline

Style reports the formatting without the text, for merging runs.

type Table

type Table struct {
	Rows [][][]Inline
}

Table is a GFM table; the first row is the header.

type UnsupportedError

type UnsupportedError struct {
	Construct string
	Line      int
	Hint      string
}

UnsupportedError names a construct the Docs API cannot take.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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