Documentation
¶
Overview ¶
Package mdindex parses a changelog once and indexes its sections by version heading.
Index ¶
- Constants
- Variables
- func Demote(src []byte) []byte
- func FromRST(src []byte) []byte
- func HeadingPattern(tmpl string) (*regexp.Regexp, error)
- func Subsection(src []byte, match func(heading string) bool) (string, string, int, bool)
- type Cache
- type FetchFunc
- type Index
- type Key
- type Options
- type Section
Constants ¶
const VersionPlaceholder = "{version}"
VersionPlaceholder is replaced by a version pattern in heading templates.
Variables ¶
var ErrNoScheme = errors.New("mdindex: no version scheme")
ErrNoScheme is returned by Parse when Options has no version scheme.
Functions ¶
func Demote ¶
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 ¶
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 ¶
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 ¶
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.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is a parsed changelog with its version sections in document order.
func (*Index) Markdown ¶
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 ¶
Newest returns the highest version among the sections. The second result is false when the document has no version section.
func (*Index) Whole ¶
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.