mdindex

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mdindex parses a changelog once and indexes its sections by version heading.

Index

Constants

View Source
const VersionPlaceholder = "{version}"

VersionPlaceholder is replaced by a version pattern in heading templates.

Variables

View Source
var ErrNoScheme = errors.New("mdindex: no version scheme")

ErrNoScheme is returned by Parse when Options has no version scheme.

Functions

func Demote

func Demote(src []byte) []byte

Demote returns src with each ATX heading one level deeper, up to level 6, so the document can sit under a new top heading. Headings in code fences are left alone.

func FromRST

func FromRST(src []byte) []byte

FromRST turns reStructuredText section titles (a line followed by an underline, with an optional overline) into ATX headings, so Parse can index CHANGES.rst-style changelogs. Levels follow the order in which adornment styles first appear, as in docutils. Other markup stays.

func HeadingPattern

func HeadingPattern(tmpl string) (*regexp.Regexp, error)

HeadingPattern compiles a registry heading template such as `^v{version}$`. The template is a regular expression in which {version} stands for the version.

func Subsection

func Subsection(src []byte, match func(heading string) bool) (string, string, int, bool)

Subsection returns the body of the first heading match accepts, up to the next heading of the same or a higher level, that heading's text and the 0-based line of src where the body starts. The last result is false when no heading matches.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache fetches each file once and parses it once per heading pattern. It is safe for concurrent use and lives for one digest.

func NewCache

func NewCache(fetch FetchFunc) *Cache

NewCache returns a cache that reads files with fetch.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, k Key, o Options) (*Index, error)

Get returns the index of the file k names, fetching and parsing it on first use. A failed fetch is remembered, so it isn't retried within the digest.

type FetchFunc

type FetchFunc func(ctx context.Context, k Key) ([]byte, error)

FetchFunc returns the content of the file k names.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index is a parsed changelog with its version sections in document order.

func Parse

func Parse(src []byte, o Options) (*Index, error)

Parse indexes src. CRLF line endings become LF first.

func (*Index) Lookup

func (x *Index) Lookup(v version.V) (Section, bool)

Lookup returns the first section whose version equals v.

func (*Index) Markdown

func (x *Index) Markdown(s Section) (string, int)

Markdown returns the body of s without HTML anchors and compare-link definitions, trimmed of blank lines, and the 1-based line it starts on.

func (*Index) Newest

func (x *Index) Newest() (version.V, bool)

Newest returns the highest version among the sections. The second result is false when the document has no version section.

func (*Index) Sections

func (x *Index) Sections() []Section

Sections returns every version section in document order.

func (*Index) Whole

func (x *Index) Whole() string

Whole returns the entire document the way Index.Markdown returns a section.

type Key

type Key struct {
	Repo, Ref, Path string
}

Key names one file: a path in a repository at a ref.

type Options

type Options struct {
	Scheme  version.Scheme
	Heading *regexp.Regexp // from [HeadingPattern]; nil means detect the version heading level
}

Options says how version headings are found.

type Section

type Section struct {
	Version     version.V
	Heading     []string // enclosing headings, then the version heading
	HeadingLine int      // 1-based line of the version heading
	Line        int      // 1-based line where the body starts
	Start, End  int      // byte range of the body
}

Section is the body of one version heading.

Jump to

Keyboard shortcuts

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