mdutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// Kind is the upper-case alert name: NOTE, TIP, IMPORTANT, WARNING, CAUTION.
	Kind string
	// Body is the quote content with the "> " markers stripped.
	Body string
}

Alert is a GFM alert blockquote, e.g. "> [!WARNING]".

type Align

type Align int

Align is a GFM table column alignment, taken from the delimiter row.

const (
	// AlignDefault leaves the column to the renderer's default (left).
	AlignDefault Align = iota
	AlignLeft
	AlignCenter
	AlignRight
)

type Block

type Block struct {
	Kind BlockKind

	// Text is the markdown source for BlockMarkdown, or the code body
	// (without fence lines) for BlockCode.
	Text string

	// Lang is the info string of a BlockCode fence; may be empty.
	Lang string

	// Table is populated for BlockTable.
	Table *Table

	// Alert is populated for BlockAlert.
	Alert *Alert

	// Image is populated for BlockImage.
	Image *Image
}

Block is one run of a document that shares a rendering strategy.

func Segment

func Segment(src string) []Block

Segment splits markdown into typed blocks so that tables, fenced code and alerts can be rendered directly instead of going through glamour, which stretches tables to the full pane width and gives code blocks no frame.

Detection is fence-aware: pipes and alert markers inside a code block are left alone.

type BlockKind

type BlockKind int

BlockKind identifies how a segment of markdown should be rendered.

const (
	// BlockMarkdown is prose handed to glamour unchanged.
	BlockMarkdown BlockKind = iota
	// BlockCode is a fenced code block rendered with our own frame.
	BlockCode
	// BlockTable is a GFM pipe table rendered with our own box drawing.
	BlockTable
	// BlockAlert is a GFM alert blockquote rendered as a callout.
	BlockAlert
	// BlockImage is an image alone on its own line, rendered as a callout.
	BlockImage
)

type FrontMatter

type FrontMatter struct {
	// Pairs holds top-level scalar keys in document order. Nested structures
	// are skipped: this is for display, not for round-tripping YAML.
	Pairs [][2]string
}

FrontMatter is document metadata parsed from a leading YAML block.

func SplitFrontMatter

func SplitFrontMatter(src string) (*FrontMatter, string)

SplitFrontMatter separates a leading "---" delimited YAML block from the document body. Documents without front matter come back unchanged.

type Image

type Image struct {
	// Alt is the alt text, empty when the source gave none.
	Alt string
	// Dest is the destination exactly as written in the document.
	Dest string
	// Remote reports whether Dest is a URL rather than a filesystem path.
	Remote bool
}

Image is a standalone image reference: one that sits alone on its own line and so reads as a block rather than as part of a sentence.

func (Image) Resolve

func (im Image) Resolve(docDir string) string

Resolve returns the image's path made absolute against docDir. Remote destinations come back unchanged.

type Section

type Section struct {
	// Title is sidebar text; Level is 0 for preamble, else 1–6.
	Title string
	Level int
	// Source is the markdown fragment for this section (including its heading line when applicable).
	Source string
}

Section is one slice of the original markdown, split at ATX headings.

func SplitByHeadings

func SplitByHeadings(src string) []Section

SplitByHeadings splits markdown into sections at ATX headings, ignoring '#' sequences inside fenced code blocks.

type Table

type Table struct {
	Headers []string
	Rows    [][]string
	Aligns  []Align
}

Table is a parsed GFM pipe table.

Jump to

Keyboard shortcuts

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