Documentation
¶
Overview ¶
Package changelog parses changelog files into structured entries.
It supports three common formats: Keep a Changelog (## [version] - date), markdown headers (## version or ### version), and setext/underline style (version\n=====). Format detection is automatic by default.
Basic usage:
p := changelog.Parse(content)
for _, v := range p.Versions() {
entry, _ := p.Entry(v)
fmt.Printf("%s: %s\n", v, entry.Content)
}
Parse a file:
p, err := changelog.ParseFile("CHANGELOG.md")
Find and parse a changelog in a directory:
p, err := changelog.FindAndParse(".")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindChangelog ¶
FindChangelog locates a changelog file in the given directory. Returns the path to the changelog file, or empty string if not found.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds the parsed changelog data and provides access methods.
func FindAndParse ¶
FindAndParse locates a changelog file in the directory and parses it.
func ParseWithFormat ¶
ParseWithFormat creates a parser using the specified format.
func ParseWithPattern ¶
ParseWithPattern creates a parser using a custom regex pattern. The pattern must have at least one capture group for the version string. An optional second capture group captures the date (YYYY-MM-DD). The (?m) flag is automatically added if not already present, so that ^ and $ match line boundaries.
func (*Parser) Between ¶
Between returns the content between two version headers. Either version can be empty to indicate the start or end of the changelog. Returns the content and true if found, or empty string and false if not.
func (*Parser) Entries ¶
Entries returns all entries as a map. Note that Go maps do not preserve insertion order; use Versions() + Entry() if order matters.
func (*Parser) LineForVersion ¶
LineForVersion returns the 0-based line number where the given version header appears, or -1 if not found. Strips a leading "v" prefix for matching.