md

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package md is a small typed Markdown builder for magus's generated docs (MAGUS.md, the insight report). It replaces hand-concatenated markdown with block-level primitives - headings, paragraphs, tables, code fences, lists - so table pipes, fence closing, and block spacing are written once here instead of at every call site. Every block method leaves exactly one blank line after itself, so blocks compose without callers tracking spacing.

It is a builder, not a renderer: output goes wherever the caller writes it (emit, never render). Cell and label text is taken verbatim - inputs are sanitized at graph ingest, and generated docs deliberately embed inline markdown (backticks, bold) in cells.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bold

func Bold(s string) string

Bold renders s bold.

func Code

func Code(s string) string

Code renders s as inline code.

func Codes

func Codes(labels []string) string

Codes renders labels as comma-separated inline code (a table cell of anchors), or "" when there are none.

func Link(text, href string) string

Link renders a markdown link.

Types

type Align

type Align int

Align is a table column alignment, rendered as the GFM delimiter cell.

const (
	Left   Align = iota // ---
	Right               // --:
	Center              // :-:
)

type Builder

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

Builder accumulates a Markdown document. The zero value is ready to use.

func (*Builder) AlignedCodeBlock

func (b *Builder) AlignedCodeBlock(lang string, lines []CodeLine)

AlignedCodeBlock writes a fenced code block of code lines with their trailing "# note" comments aligned into one column. A line with an empty note carries no comment.

func (*Builder) Bytes

func (b *Builder) Bytes() []byte

Bytes returns the accumulated document.

func (*Builder) CodeBlock

func (b *Builder) CodeBlock(lang string, lines ...string)

CodeBlock writes a fenced code block with one line per entry.

func (*Builder) Comment

func (b *Builder) Comment(text string)

Comment writes an HTML comment block (e.g. the "generated, do not edit" marker).

func (*Builder) Details

func (b *Builder) Details(summary string, body func(*Builder))

Details writes a <details> disclosure block: the summary line, a blank line, then whatever body writes into the builder.

func (*Builder) Fenced

func (b *Builder) Fenced(lang string, emit func(io.Writer) error) error

Fenced writes a fenced block whose body comes from emit (e.g. a Mermaid emitter that takes an io.Writer). The fence is closed even when emit fails, but the error is returned as-is.

func (*Builder) Grow

func (b *Builder) Grow(n int)

Grow hints the final document size, like bytes.Buffer.Grow.

func (*Builder) Heading

func (b *Builder) Heading(level int, text string)

Heading writes an ATX heading at the given level (1-6).

func (*Builder) List

func (b *Builder) List(items ...string)

List writes a bullet list, one "- item" line per entry. No-op when empty.

func (*Builder) Paragraph

func (b *Builder) Paragraph(text string)

Paragraph writes text as its own block.

func (*Builder) Paragraphf

func (b *Builder) Paragraphf(format string, args ...any)

Paragraphf writes a formatted paragraph block.

func (*Builder) Quote added in v0.4.0

func (b *Builder) Quote(lines ...string)

Quote writes a blockquote block, one "> line" per entry. Unlike Comment it renders, so it suits a note the reader is meant to see. No-op when empty.

func (*Builder) Raw

func (b *Builder) Raw(s string)

Raw writes s verbatim - the escape hatch for shapes the primitives don't cover. Callers own the trailing blank line.

func (*Builder) Table

func (b *Builder) Table(header []string, align []Align, rows [][]string)

Table writes a GFM table: a header row, the alignment delimiter row, then one row per entry. align may be nil (all Left) or shorter than header (the tail defaults to Left). Cells are written verbatim; callers pre-format values (and may embed inline code). No-op when there are no rows.

func (*Builder) WriteTo

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

WriteTo writes the accumulated document to w.

type CodeLine

type CodeLine struct{ Code, Note string }

CodeLine is one line of an AlignedCodeBlock: the code and its comment.

Jump to

Keyboard shortcuts

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