Documentation
¶
Index ¶
- type Builder
- func (m *Builder) BlockQuote(text ...string) *Builder
- func (m *Builder) BlockQuoteWith(fn func(*Builder)) *Builder
- func (m *Builder) Bold(parts ...string) *Builder
- func (m *Builder) BoldWords(parts ...string) *Builder
- func (m *Builder) BulletList(items ...string) *Builder
- func (m *Builder) BulletListItem(item ...string) *Builder
- func (m *Builder) BulletListItemWords(words ...string) *Builder
- func (m *Builder) ExtendBulletList(seq iter.Seq[string]) *Builder
- func (m *Builder) ExtendKV(seq iter.Seq2[string, string]) *Builder
- func (m *Builder) ExtendKVSeq(seq iter.Seq[irt.KV[string, string]]) *Builder
- func (m *Builder) ExtendKVany(seq iter.Seq2[string, any]) *Builder
- func (m *Builder) ExtendKVanySeq(seq iter.Seq[irt.KV[string, any]]) *Builder
- func (m *Builder) ExtendOrderedList(seq iter.Seq[string]) *Builder
- func (m *Builder) FencedCode(lang, code string) *Builder
- func (m *Builder) FencedCodeWith(lang string, fn func(*Builder)) *Builder
- func (m *Builder) Format(f fmt.State, verb rune)
- func (m *Builder) FromKV(kv irt.KV[string, string]) *Builder
- func (m *Builder) FromKVany(kv irt.KV[string, any]) *Builder
- func (m *Builder) H1(text ...string) *Builder
- func (m *Builder) H1Words(words ...string) *Builder
- func (m *Builder) H2(text ...string) *Builder
- func (m *Builder) H2Words(words ...string) *Builder
- func (m *Builder) H3(text ...string) *Builder
- func (m *Builder) H3Words(words ...string) *Builder
- func (m *Builder) H4(text ...string) *Builder
- func (m *Builder) H4Words(words ...string) *Builder
- func (m *Builder) H5(text ...string) *Builder
- func (m *Builder) H5Words(words ...string) *Builder
- func (m *Builder) H6(text ...string) *Builder
- func (m *Builder) H6Words(words ...string) *Builder
- func (m *Builder) IndentWith(indent string, fn func(*Builder)) *Builder
- func (m *Builder) IndentedCode(code string) *Builder
- func (m *Builder) IndentedCodeWith(fn func(*Builder)) *Builder
- func (m *Builder) Italic(parts ...string) *Builder
- func (m *Builder) ItalicParagraph(text ...string) *Builder
- func (m *Builder) ItalicWords(parts ...string) *Builder
- func (m *Builder) KV(key, val string) *Builder
- func (mb *Builder) KVTable(header irt.KV[string, string], seq iter.Seq2[string, string]) *Builder
- func (m *Builder) KVany(k string, v any) *Builder
- func (m *Builder) KVanys(kvs ...irt.KV[string, any]) *Builder
- func (m *Builder) KVs(kvs ...irt.KV[string, string]) *Builder
- func (m *Builder) Link(text, url string) *Builder
- func (m *Builder) NewTable(cols ...Column) *Table
- func (m *Builder) NewTableWithColumns(cols []Column) *Table
- func (m *Builder) OrderedList(items ...string) *Builder
- func (m *Builder) OrderedListItem(item ...string) *Builder
- func (m *Builder) OrderedListItemWords(words ...string) *Builder
- func (m *Builder) Paragraph(text ...string) *Builder
- func (m *Builder) ParagraphBreak() *Builder
- func (m *Builder) ParagraphWords(words ...string) *Builder
- func (m *Builder) Preformatted(parts ...string) *Builder
- func (m *Builder) PreformattedWords(parts ...string) *Builder
- func (m *Builder) PushBytes(b []byte) *Builder
- func (m *Builder) PushConcat(parts ...string) *Builder
- func (m *Builder) PushFromKV(kv irt.KV[string, string]) *Builder
- func (m *Builder) PushFromKVany(kv irt.KV[string, any]) *Builder
- func (m *Builder) PushKV(key, val string) *Builder
- func (m *Builder) PushKVany(key string, val any) *Builder
- func (m *Builder) PushLine() *Builder
- func (m *Builder) PushNLines(n int) *Builder
- func (m *Builder) PushString(s string) *Builder
- func (m *Builder) Release()
- func (m *Builder) Strikethrough(parts ...string) *Builder
- func (m *Builder) StrikethroughWords(parts ...string) *Builder
- func (m *Builder) Text(parts ...string) *Builder
- func (m *Builder) TextWords(parts ...string) *Builder
- func (m *Builder) Truncate(targetSize int)
- func (m *Builder) WriteTo(w io.Writer) (int64, error)
- type Column
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
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 ¶
MakeBuilder returns a new Builder pre-allocated to the given byte capacity.
func (*Builder) BlockQuote ¶
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 ¶
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 ¶
Bold writes **parts** to the builder. Multiple parts are concatenated directly without a separator. Use BoldWords to join parts with spaces.
func (*Builder) BoldWords ¶
BoldWords writes **parts** to the builder with parts joined by a single space.
func (*Builder) BulletList ¶
BulletList writes an unordered list followed by a blank line. Does nothing if no items are provided.
func (*Builder) BulletListItem ¶
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 ¶
BulletListItemWords writes a single "- words..." line with parts joined by a single space.
func (*Builder) ExtendBulletList ¶
ExtendBulletList writes an unordered list from a sequence, followed by a blank line. Does nothing if the sequence is empty.
func (*Builder) ExtendKVSeq ¶
ExtendKVSeq writes a KV line for each irt.KV[string, string] yielded by seq.
func (*Builder) ExtendKVany ¶
ExtendKVany writes a KV line for each pair yielded by seq, formatting values with %v.
func (*Builder) ExtendKVanySeq ¶
ExtendKVanySeq writes a KV line for each irt.KV[string, any] yielded by seq, formatting values with %v.
func (*Builder) ExtendOrderedList ¶
ExtendOrderedList writes a numbered list from a sequence, followed by a blank line. Does nothing if the sequence is empty.
func (*Builder) FencedCode ¶
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 ¶
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 ¶
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 ¶
FromKV writes a **key**: value line followed by a newline, reading key and value from an irt.KV[string, string].
func (*Builder) FromKVany ¶
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 ¶
H1 writes a level-1 heading ("# text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H1Words ¶
H1Words writes a level-1 heading with parts joined by a single space, followed by a blank line.
func (*Builder) H2 ¶
H2 writes a level-2 heading ("## text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H2Words ¶
H2Words writes a level-2 heading with parts joined by a single space, followed by a blank line.
func (*Builder) H3 ¶
H3 writes a level-3 heading ("### text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H3Words ¶
H3Words writes a level-3 heading with parts joined by a single space, followed by a blank line.
func (*Builder) H4 ¶
H4 writes a level-4 heading ("#### text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H4Words ¶
H4Words writes a level-4 heading with parts joined by a single space, followed by a blank line.
func (*Builder) H5 ¶
H5 writes a level-5 heading ("##### text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H5Words ¶
H5Words writes a level-5 heading with parts joined by a single space, followed by a blank line.
func (*Builder) H6 ¶
H6 writes a level-6 heading ("###### text") followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) H6Words ¶
H6Words writes a level-6 heading with parts joined by a single space, followed by a blank line.
func (*Builder) IndentWith ¶
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 ¶
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 ¶
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 ¶
Italic writes _parts_ to the builder. Multiple parts are concatenated directly without a separator. Use ItalicWords to join parts with spaces.
func (*Builder) ItalicParagraph ¶
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 ¶
ItalicWords writes _parts_ to the builder with parts joined by a single space.
func (*Builder) KVTable ¶
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 ¶
KVany writes a **key**: value line followed by a newline, formatting value with %v.
func (*Builder) NewTable ¶
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 ¶
NewTableWithColumns creates a Table from a slice of column definition.
func (*Builder) OrderedList ¶
OrderedList writes a numbered list followed by a blank line. Does nothing if no items are provided.
func (*Builder) OrderedListItem ¶
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 ¶
OrderedListItemWords writes a single "1. words..." line with parts joined by a single space.
func (*Builder) Paragraph ¶
Paragraph writes text followed by a blank line. Multiple parts are concatenated directly without a separator.
func (*Builder) ParagraphBreak ¶
ParagraphBreak writes two newlines, creating a markdown paragraph separator.
func (*Builder) ParagraphWords ¶
ParagraphWords writes parts joined with spaces followed by a blank line.
func (*Builder) Preformatted ¶
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 ¶
PreformattedWords writes `parts` to the builder as an inline code span with parts joined by a single space.
func (*Builder) PushBytes ¶
PushBytes appends b to the builder and returns the receiver for chaining.
func (*Builder) PushConcat ¶
PushConcat appends all parts concatenated to the builder and returns the receiver for chaining.
func (*Builder) PushFromKV ¶
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 ¶
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 ¶
PushKV writes a **key**: value line followed by a newline and returns the receiver for chaining.
func (*Builder) PushKVany ¶
PushKVany writes a **key**: value line followed by a newline, formatting value with %v, and returns the receiver for chaining.
func (*Builder) PushLine ¶
PushLine appends a newline to the builder and returns the receiver for chaining.
func (*Builder) PushNLines ¶
PushNLines appends n newlines to the builder and returns the receiver for chaining.
func (*Builder) PushString ¶
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 ¶
Strikethrough writes ~~parts~~ to the builder. Multiple parts are concatenated directly without a separator. Use StrikethroughWords to join parts with spaces.
func (*Builder) StrikethroughWords ¶
StrikethroughWords writes ~~parts~~ to the builder with parts joined by a single space.
func (*Builder) Text ¶
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 ¶
TextWords writes parts joined with spaces to the builder and returns the receiver for chaining.
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 ¶
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) ExtendRow ¶
ExtendRow appends a single data row from a sequence. Cells are pipe-escaped immediately. Iterates directly to avoid an intermediate []string allocation.