parser

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const PseudoHeadingLevel = 7

PseudoHeadingLevel is the heading level assigned to pseudo-headings.

Variables

This section is empty.

Functions

func AutoSplitParagraphs

func AutoSplitParagraphs(blocks []model.Block, cfg PseudoHeadingConfig, source []byte) []model.Block

AutoSplitParagraphs splits paragraph blocks at lines that are pseudo-heading candidates. This ensures that pseudo-heading-like lines buried inside a large paragraph (due to goldmark merging consecutive non-blank lines) become independent blocks that DetectPseudoHeadings can then promote. The function is a no-op when cfg.Enabled is false.

func CompilePrefixPatterns

func CompilePrefixPatterns(patterns []string) []*regexp.Regexp

CompilePrefixPatterns compiles PrefixPatterns from config, skipping invalid ones.

func DetectPseudoHeadings

func DetectPseudoHeadings(blocks []model.Block, cfg PseudoHeadingConfig) []model.Block

DetectPseudoHeadings promotes short paragraph blocks that look like headings. Promoted blocks get Kind=BlockHeading, HeadingLevel=7, IsPseudoHeading=true. After promotion, heading paths are rebuilt.

func IsPseudoHeadingCandidate

func IsPseudoHeadingCandidate(text string, cfg PseudoHeadingConfig, prefixRes []*regexp.Regexp) bool

IsPseudoHeadingCandidate returns true if the given text looks like a pseudo-heading according to the config rules (ColonSuffix, NumberedItems, PrefixPatterns, MaxRuneLen, ExcludePatterns). The text should already be TrimSpace'd. prefixRes is the pre-compiled PrefixPatterns (use compilePrefixPatterns).

func Parse

func Parse(source []byte) ([]model.Block, error)

Parse parses markdown source into a slice of Blocks with source ranges and heading paths.

func SplitLongParagraphs

func SplitLongParagraphs(blocks []model.Block, patterns []*regexp.Regexp, source []byte) []model.Block

SplitLongParagraphs splits paragraph blocks at lines matching any of the given patterns. Non-paragraph blocks are passed through unchanged. The source parameter is needed to recalculate SourceRange byte offsets.

Types

type PseudoHeadingConfig

type PseudoHeadingConfig struct {
	Enabled         bool
	MaxRuneLen      int      // Maximum rune length for candidate lines (default 40)
	ColonSuffixes   bool     // Detect lines ending with : or :
	NumberedItems   bool     // Detect lines starting with \d+)
	ExcludePatterns []string // Partial-match patterns to exclude from promotion
	PrefixPatterns  []string // Regex patterns to match line start (bypasses MaxRuneLen)
}

PseudoHeadingConfig configures pseudo-heading detection.

func DefaultPseudoHeadingConfig

func DefaultPseudoHeadingConfig() PseudoHeadingConfig

DefaultPseudoHeadingConfig returns a config with sensible defaults.

Jump to

Keyboard shortcuts

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