markdown

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT-0 Imports: 2 Imported by: 0

Documentation

Overview

Package markdown provides shared utilities for Markdown parsing and tokenization. This package is intended for use by the various md-tools binaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExcludeRanges

func ExcludeRanges(content string, contentStart int, ranges []ByteRange) string

ExcludeRanges returns content with any overlapping ranges removed. contentStart is the byte offset where content begins in the original source. Ranges are specified in terms of the original source byte positions.

func IsFootnoteContinuation

func IsFootnoteContinuation(line string) bool

IsFootnoteContinuation returns true if the line continues the body of a preceding footnote definition: a non-blank line that does not itself start another block-level construct.

func IsFootnoteDefinition

func IsFootnoteDefinition(line string) bool

IsFootnoteDefinition returns true if the line starts a footnote definition. Footnote definitions have the form [^label]: ...

func IsHorizontalRule

func IsHorizontalRule(line string) bool

IsHorizontalRule returns true if the line is a horizontal rule. Horizontal rules are three or more -, *, or _ characters with optional spaces.

func IsLinkRefDefinition

func IsLinkRefDefinition(line string) bool

IsLinkRefDefinition returns true if the line is a link reference definition. Link reference definitions have the form [label]: URL This excludes footnote definitions.

func IsListItem

func IsListItem(line string) bool

IsListItem returns true if the line is a list item. Supports unordered lists (-, *, +) and ordered lists (1., 2., etc).

func IsTableRow

func IsTableRow(line string) bool

IsTableRow returns true if the line is a GFM table row. GFM table rows start with a pipe character.

func LooksLikeFrontmatterProperty

func LooksLikeFrontmatterProperty(line string) bool

LooksLikeFrontmatterProperty returns true if the line appears to be a YAML frontmatter property (contains a colon not at the start).

func SplitFrontmatter

func SplitFrontmatter(content string) (frontmatter, body string)

SplitFrontmatter separates a leading YAML frontmatter block from the document body. When there is no frontmatter, frontmatter is empty and body is content; otherwise the two rejoin as frontmatter + "\n" + body.

func Transform

func Transform(content string, h Handlers) string

Transform applies a Markdown-aware transformation to content, routing each block-level construct to the appropriate handler or emitting it unchanged. Frontmatter, code blocks, headers, list items (with continuations), table rows, and horizontal rules are passed through; paragraphs and blockquotes are delegated to h.

func TransformBlockquote

func TransformBlockquote(lines []string, flush func([]string) []string) []string

TransformBlockquote applies a blockquote-aware transformation to consecutive blockquote lines. The flush function receives accumulated content lines with the "> " prefix stripped, and must return the transformed output lines with the prefix added back. GFM alert headers and table rows are emitted as-is without passing through flush.

Types

type ByteRange

type ByteRange struct {
	Start int
	End   int
}

ByteRange represents a range of bytes in source content.

type Handlers

type Handlers struct {
	// Paragraph is called with the collected lines of a regular paragraph and
	// returns the transformed lines.
	Paragraph func(lines []string) []string
	// Blockquote is called with consecutive blockquote lines ("> " prefix
	// intact) and returns the transformed lines.
	Blockquote func(lines []string) []string
	// Footnote is called with a footnote definition's lines (the "[^label]:"
	// line plus any continuation lines) and returns the transformed lines.
	// When nil, footnote definitions are emitted verbatim.
	Footnote func(lines []string) []string
}

Handlers defines the tool-specific behavior for paragraph and blockquote processing in a Markdown document transformation.

Jump to

Keyboard shortcuts

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