mdparse

package
v0.0.0-...-9fe12d6 Latest Latest
Warning

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

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

Documentation

Overview

Package mdparse provides goldmark-based helpers for inspecting markdown structure, used by the atomic-validate spec and config validators. Every function takes source bytes, so the package needs no filesystem access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindTableByHeader

func FindTableByHeader(src []byte, header []string) (found bool, lineNumber int, err error)

FindTableByHeader locates the first table whose header cells exactly match the given titles in order, returning the header row's 1-indexed line.

func FindTableByRequiredColumns

func FindTableByRequiredColumns(src []byte, required []string) (found bool, lineNumber int, err error)

FindTableByRequiredColumns is FindTableByHeader relaxed to an ordered subsequence: required titles must appear left to right, but extra columns between or after them are allowed.

func IsATXOnly

func IsATXOnly(src []byte) bool

IsATXOnly reports whether src contains no Setext headings.

Line prescan rather than AST inspection: goldmark exposes no "is setext" flag on Heading, and deriving line spans from segment offsets invites off-by-ones. Fenced blocks are skipped so embedded examples don't false-positive; indented blocks need no skip, since their leading space already fails isSetextUnderline.

Types

type InlineRef

type InlineRef struct {
	Kind string // "code" | "link"
	Text string // code-span inner text, or link destination
	Line int    // 1-indexed line number in source
}

InlineRef is a code span or link extracted from markdown prose (outside code blocks).

func InlineRefs

func InlineRefs(src []byte) ([]InlineRef, error)

InlineRefs collects code spans and links, skipping code-block subtrees.

type Section

type Section struct {
	Heading string
	Level   int
	// Start is the heading's own 1-indexed line; End is the section's last
	// line, or 0 when the section runs to the end of the file.
	Start int
	End   int
}

Section describes a heading-bounded block in a markdown document.

func Sections

func Sections(src []byte) ([]Section, error)

Sections returns heading-bounded blocks with 1-indexed line numbers. H1 and H2 open sections; H3+ is absorbed into the enclosing one, matching this project's spec layout where H2 is the bracketing level.

type TextSegment

type TextSegment struct {
	Text string
	Line int
}

TextSegment is a run of prose outside any code block. Line is its 1-indexed start; Text may span multiple lines.

func TextSegments

func TextSegments(src []byte) []TextSegment

TextSegments extracts prose from src, skipping fenced and indented code blocks so the config validator's regexes don't match embedded examples.

Only block-level code is skipped: a pattern inside an inline `backtick span` still matches. Deliberate — such spans are rare for these patterns.

Jump to

Keyboard shortcuts

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