mdwn

package
v0.14.9 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct{ strut.Mutable }

Builder wraps strut.Mutable with methods for writing markdown elements. Many methods return the receiver for chaining. Call String() or WriteTo to get the result.

func MakeBuilder

func MakeBuilder(capacity int) *Builder

MakeBuilder returns a new Builder pre-allocated to the given byte capacity.

func (*Builder) BlockQuote

func (m *Builder) BlockQuote(text ...string) *Builder

BlockQuote prefixes each line of text with "> " and appends a blank line. Multiple parts are concatenated directly before quoting. Blank lines within the text are preserved so nested markdown elements render correctly. Trailing newlines are trimmed; text consisting solely of newlines (or empty string) produces no output.

func (*Builder) BlockQuoteWith

func (m *Builder) BlockQuoteWith(fn func(*Builder)) *Builder

BlockQuoteWith builds inner content using the provided function and wraps the result in a block quote, enabling nested block-quote elements. Uses the underlying byte buffer directly to avoid an intermediate string copy.

func (*Builder) Bold

func (m *Builder) Bold(parts ...string) *Builder

Bold writes **parts** to the builder. Multiple parts are concatenated directly without a separator. Use BoldWords to join parts with spaces.

func (*Builder) BoldWords

func (m *Builder) BoldWords(parts ...string) *Builder

BoldWords writes **parts** to the builder with parts joined by a single space.

func (*Builder) BulletList

func (m *Builder) BulletList(items ...string) *Builder

BulletList writes an unordered list followed by a blank line. Does nothing if no items are provided.

func (*Builder) BulletListItem

func (m *Builder) BulletListItem(item ...string) *Builder

BulletListItem writes a single "- item" line. Multiple parts are concatenated directly to form one item's text — they do not produce multiple list items. For multiple items use BulletList.

func (*Builder) BulletListItemWords

func (m *Builder) BulletListItemWords(words ...string) *Builder

BulletListItemWords writes a single "- words..." line with parts joined by a single space.

func (*Builder) ExtendBulletList

func (m *Builder) ExtendBulletList(seq iter.Seq[string]) *Builder

ExtendBulletList writes an unordered list from a sequence, followed by a blank line. Does nothing if the sequence is empty.

func (*Builder) ExtendKV

func (m *Builder) ExtendKV(seq iter.Seq2[string, string]) *Builder

ExtendKV writes a KV line for each pair yielded by seq.

func (*Builder) ExtendKVSeq

func (m *Builder) ExtendKVSeq(seq iter.Seq[irt.KV[string, string]]) *Builder

ExtendKVSeq writes a KV line for each irt.KV[string, string] yielded by seq.

func (*Builder) ExtendKVany

func (m *Builder) ExtendKVany(seq iter.Seq2[string, any]) *Builder

ExtendKVany writes a KV line for each pair yielded by seq, formatting values with %v.

func (*Builder) ExtendKVanySeq

func (m *Builder) ExtendKVanySeq(seq iter.Seq[irt.KV[string, any]]) *Builder

ExtendKVanySeq writes a KV line for each irt.KV[string, any] yielded by seq, formatting values with %v.

func (*Builder) ExtendOrderedList

func (m *Builder) ExtendOrderedList(seq iter.Seq[string]) *Builder

ExtendOrderedList writes a numbered list from a sequence, followed by a blank line. Does nothing if the sequence is empty.

func (*Builder) FencedCode

func (m *Builder) FencedCode(lang, code string) *Builder

FencedCode writes a fenced code block. lang is written as the language identifier on the opening fence (e.g. "go", "sh"); pass "" for no tag. If code does not already end with a newline, one is appended before the closing fence.

func (*Builder) FencedCodeWith

func (m *Builder) FencedCodeWith(lang string, fn func(*Builder)) *Builder

FencedCodeWith builds inner content using the provided function and wraps the result in a fenced code block with an optional language identifier. Returns m unchanged if fn produces no content.

func (*Builder) Format

func (m *Builder) Format(f fmt.State, verb rune)

Format implements fmt.Formatter. For the %s and %v verbs it writes the accumulated content directly to f without allocating an intermediate string. This makes Builder usable in fmt.Fprintf and similar calls without String().

func (*Builder) FromKV

func (m *Builder) FromKV(kv irt.KV[string, string]) *Builder

FromKV writes a **key**: value line followed by a newline, reading key and value from an irt.KV[string, string].

func (*Builder) FromKVany

func (m *Builder) FromKVany(kv irt.KV[string, any]) *Builder

FromKVany writes a **key**: value line followed by a newline, reading key and value from an irt.KV[string, any] and formatting the value with %v.

func (*Builder) H1

func (m *Builder) H1(text ...string) *Builder

H1 writes a level-1 heading ("# text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H1Words

func (m *Builder) H1Words(words ...string) *Builder

H1Words writes a level-1 heading with parts joined by a single space, followed by a blank line.

func (*Builder) H2

func (m *Builder) H2(text ...string) *Builder

H2 writes a level-2 heading ("## text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H2Words

func (m *Builder) H2Words(words ...string) *Builder

H2Words writes a level-2 heading with parts joined by a single space, followed by a blank line.

func (*Builder) H3

func (m *Builder) H3(text ...string) *Builder

H3 writes a level-3 heading ("### text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H3Words

func (m *Builder) H3Words(words ...string) *Builder

H3Words writes a level-3 heading with parts joined by a single space, followed by a blank line.

func (*Builder) H4

func (m *Builder) H4(text ...string) *Builder

H4 writes a level-4 heading ("#### text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H4Words

func (m *Builder) H4Words(words ...string) *Builder

H4Words writes a level-4 heading with parts joined by a single space, followed by a blank line.

func (*Builder) H5

func (m *Builder) H5(text ...string) *Builder

H5 writes a level-5 heading ("##### text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H5Words

func (m *Builder) H5Words(words ...string) *Builder

H5Words writes a level-5 heading with parts joined by a single space, followed by a blank line.

func (*Builder) H6

func (m *Builder) H6(text ...string) *Builder

H6 writes a level-6 heading ("###### text") followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) H6Words

func (m *Builder) H6Words(words ...string) *Builder

H6Words writes a level-6 heading with parts joined by a single space, followed by a blank line.

func (*Builder) IndentWith

func (m *Builder) IndentWith(indent string, fn func(*Builder)) *Builder

IndentWith builds inner content using the provided function and prefixes each line of the result with indent, followed by a blank line. Useful for code blocks beneath list items (4-space indent) or other indented sections. Returns m unchanged if fn produces no content.

func (*Builder) IndentedCode

func (m *Builder) IndentedCode(code string) *Builder

IndentedCode writes code as a 4-space indented code block (CommonMark alternative to fenced code blocks). Trailing newlines are trimmed. Returns m unchanged if code is empty.

func (*Builder) IndentedCodeWith

func (m *Builder) IndentedCodeWith(fn func(*Builder)) *Builder

IndentedCodeWith builds inner content using the provided function and writes it as a 4-space indented code block. Returns m unchanged if fn produces no content.

func (*Builder) Italic

func (m *Builder) Italic(parts ...string) *Builder

Italic writes _parts_ to the builder. Multiple parts are concatenated directly without a separator. Use ItalicWords to join parts with spaces.

func (*Builder) ItalicParagraph

func (m *Builder) ItalicParagraph(text ...string) *Builder

ItalicParagraph writes _text_ followed by a blank line. Multiple parts are concatenated directly without a separator before the italic markers are applied.

func (*Builder) ItalicWords

func (m *Builder) ItalicWords(parts ...string) *Builder

ItalicWords writes _parts_ to the builder with parts joined by a single space.

func (*Builder) KV

func (m *Builder) KV(key, val string) *Builder

KV writes a **key**: value line followed by a newline.

func (*Builder) KVTable

func (mb *Builder) KVTable(header irt.KV[string, string], seq iter.Seq2[string, string]) *Builder

KVTable builds a two-column key/value table from a two-value sequence and calls Build. The header parameter names the key and value columns. Values are formatted with fmt.Sprint.

func (*Builder) KVany

func (m *Builder) KVany(k string, v any) *Builder

KVany writes a **key**: value line followed by a newline, formatting value with %v.

func (*Builder) KVanys

func (m *Builder) KVanys(kvs ...irt.KV[string, any]) *Builder

KVanys writes a KV line for each irt.KV[string, any] argument.

func (*Builder) KVs

func (m *Builder) KVs(kvs ...irt.KV[string, string]) *Builder

KVs writes a KV line for each irt.KV[string, string] argument.

func (m *Builder) Link(text, url string) *Builder

Link writes [text](url) to the builder.

func (*Builder) NewTable

func (m *Builder) NewTable(cols ...Column) *Table

NewTable creates a Table attached to this Builder. Call Row on the returned builder to accumulate rows, then Build to render the table and resume chaining on Builder.

func (*Builder) NewTableWithColumns

func (m *Builder) NewTableWithColumns(cols []Column) *Table

NewTableWithColumns creates a Table from a slice of column definition.

func (*Builder) OrderedList

func (m *Builder) OrderedList(items ...string) *Builder

OrderedList writes a numbered list followed by a blank line. Does nothing if no items are provided.

func (*Builder) OrderedListItem

func (m *Builder) OrderedListItem(item ...string) *Builder

OrderedListItem writes a single "1. item" line. Multiple parts are concatenated directly to form one item's text — they do not produce multiple list items. For multiple items use OrderedList. Markdown renderers auto-number ordered list items regardless of the literal number used.

func (*Builder) OrderedListItemWords

func (m *Builder) OrderedListItemWords(words ...string) *Builder

OrderedListItemWords writes a single "1. words..." line with parts joined by a single space.

func (*Builder) Paragraph

func (m *Builder) Paragraph(text ...string) *Builder

Paragraph writes text followed by a blank line. Multiple parts are concatenated directly without a separator.

func (*Builder) ParagraphBreak

func (m *Builder) ParagraphBreak() *Builder

ParagraphBreak writes two newlines, creating a markdown paragraph separator.

func (*Builder) ParagraphWords

func (m *Builder) ParagraphWords(words ...string) *Builder

ParagraphWords writes parts joined with spaces followed by a blank line.

func (*Builder) Preformatted

func (m *Builder) Preformatted(parts ...string) *Builder

Preformatted writes `parts` to the builder as an inline code span. Multiple parts are concatenated directly without a separator. Use PreformattedWords to join parts with spaces.

func (*Builder) PreformattedWords

func (m *Builder) PreformattedWords(parts ...string) *Builder

PreformattedWords writes `parts` to the builder as an inline code span with parts joined by a single space.

func (*Builder) PushBytes

func (m *Builder) PushBytes(b []byte) *Builder

PushBytes appends b to the builder and returns the receiver for chaining.

func (*Builder) PushConcat

func (m *Builder) PushConcat(parts ...string) *Builder

PushConcat appends all parts concatenated to the builder and returns the receiver for chaining.

func (*Builder) PushFromKV

func (m *Builder) PushFromKV(kv irt.KV[string, string]) *Builder

PushFromKV writes a **key**: value line from an irt.KV[string, string] followed by a newline and returns the receiver for chaining.

func (*Builder) PushFromKVany

func (m *Builder) PushFromKVany(kv irt.KV[string, any]) *Builder

PushFromKVany writes a **key**: value line from an irt.KV[string, any] followed by a newline, formatting the value with %v, and returns the receiver for chaining.

func (*Builder) PushKV

func (m *Builder) PushKV(key, val string) *Builder

PushKV writes a **key**: value line followed by a newline and returns the receiver for chaining.

func (*Builder) PushKVany

func (m *Builder) PushKVany(key string, val any) *Builder

PushKVany writes a **key**: value line followed by a newline, formatting value with %v, and returns the receiver for chaining.

func (*Builder) PushLine

func (m *Builder) PushLine() *Builder

PushLine appends a newline to the builder and returns the receiver for chaining.

func (*Builder) PushNLines

func (m *Builder) PushNLines(n int) *Builder

PushNLines appends n newlines to the builder and returns the receiver for chaining.

func (*Builder) PushString

func (m *Builder) PushString(s string) *Builder

PushString appends s to the builder and returns the receiver for chaining.

func (*Builder) Release

func (m *Builder) Release()

Release returns the Builder's underlying buffer to the pool. The Builder must not be used after Release is called.

func (*Builder) Strikethrough

func (m *Builder) Strikethrough(parts ...string) *Builder

Strikethrough writes ~~parts~~ to the builder. Multiple parts are concatenated directly without a separator. Use StrikethroughWords to join parts with spaces.

func (*Builder) StrikethroughWords

func (m *Builder) StrikethroughWords(parts ...string) *Builder

StrikethroughWords writes ~~parts~~ to the builder with parts joined by a single space.

func (*Builder) Text

func (m *Builder) Text(parts ...string) *Builder

Text writes parts concatenated to the builder and returns the receiver for chaining. Use this to intersperse plain text with inline formatting methods:

mb.Bold("Note").Text(": see ").Link("docs", url).ParagraphBreak()

func (*Builder) TextWords

func (m *Builder) TextWords(parts ...string) *Builder

TextWords writes parts joined with spaces to the builder and returns the receiver for chaining.

func (*Builder) Truncate

func (m *Builder) Truncate(targetSize int)

Truncate shortens the Builder's content to targetSize bytes, clamped to [0, Len()]. It does not release memory; use Release to return the buffer to the pool when the Builder is no longer needed.

func (*Builder) WriteTo

func (m *Builder) WriteTo(w io.Writer) (int64, error)

WriteTo drains the accumulated content to w without copying to an intermediate string.

type Column

type Column struct {
	Name        string
	RightAlign  bool
	MinWidth    int    // minimum column width; 0 means auto-size to content
	MaxWidth    int    // maximum column width; 0 means unlimited; truncates with TruncMarker
	TruncMarker string // suffix appended to truncated cells; defaults to "..."
}

Column describes a single column in a markdown table.

type Table

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

Table accumulates table rows and renders a column-aligned markdown table when Build is called. Cells are pipe-escaped at insertion time using pooled strut.Mutable buffers; Build releases them after rendering.

func (*Table) Build

func (t *Table) Build() *Builder

Build renders the accumulated table into the parent Builder and returns it for further chaining. Column widths are auto-sized to content, lower-bounded by ColumnDef.MinWidth, at least 3 (minimum for a valid markdown separator), and capped by ColumnDef.MaxWidth when set. Cells exceeding MaxWidth are truncated with ColumnDef.TruncMarker ("..."). The pooled Mutable cell buffers are released after rendering.

func (*Table) Extend

func (t *Table) Extend(seq iter.Seq[[]string]) *Table

Extend appends rows from a sequence to the table.

func (*Table) ExtendRow

func (t *Table) ExtendRow(seq iter.Seq[string]) *Table

ExtendRow appends a single data row from a sequence. Cells are pipe-escaped immediately. Iterates directly to avoid an intermediate []string allocation.

func (*Table) Row

func (t *Table) Row(cells ...string) *Table

Row appends a single data row. Cells are pipe-escaped immediately.

func (*Table) Rows

func (t *Table) Rows(rows [][]string) *Table

Rows appends multiple data rows to the table.

Jump to

Keyboard shortcuts

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