Documentation
¶
Index ¶
- Constants
- func AutoSplitParagraphs(blocks []model.Block, cfg PseudoHeadingConfig, source []byte) []model.Block
- func CompilePrefixPatterns(patterns []string) []*regexp.Regexp
- func DetectPseudoHeadings(blocks []model.Block, cfg PseudoHeadingConfig) []model.Block
- func IsPseudoHeadingCandidate(text string, cfg PseudoHeadingConfig, prefixRes []*regexp.Regexp) bool
- func Parse(source []byte) ([]model.Block, error)
- func SplitLongParagraphs(blocks []model.Block, patterns []*regexp.Regexp, source []byte) []model.Block
- type PseudoHeadingConfig
Constants ¶
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 ¶
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 ¶
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.