renderer

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package renderer provides deterministic Markdown rendering for changelogs.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPreset = errors.New("invalid preset")

ErrInvalidPreset is returned when an invalid options preset name is provided.

Functions

func RenderMarkdown

func RenderMarkdown(cl *changelog.Changelog) string

RenderMarkdown renders a changelog to Keep a Changelog formatted Markdown. The output is deterministic: same input always produces identical output.

func RenderMarkdownWithOptions

func RenderMarkdownWithOptions(cl *changelog.Changelog, opts Options) string

RenderMarkdownWithOptions renders a changelog with custom options.

Types

type Config added in v0.4.0

type Config struct {
	Preset             string   // default, minimal, full, core, standard
	MaxTier            string   // optional tier override
	Locale             string   // optional BCP 47 locale tag override
	LocaleOverrides    string   // optional path to locale override JSON file
	AllReleases        bool     // include all releases (overrides default notable-only)
	NotableCategories  []string // custom notable categories (uses default if empty)
	ExcludeCategories  []string // categories to omit entirely (appended to preset)
	CollapseCategories []string // categories to render as a summary line (appended to preset)
	ExpandCategories   []string // categories to force-expand, overriding preset collapse defaults
}

Config holds configuration for rendering options.

type Options

type Options struct {
	// IncludeReferences includes issue/PR links in entries.
	IncludeReferences bool

	// IncludeCommits includes commit SHAs in references.
	IncludeCommits bool

	// LinkReferences creates hyperlinks for issues, PRs, and commits
	// when a repository URL is available. Requires IncludeReferences.
	LinkReferences bool

	// IncludeAuthors appends author attribution for external contributors.
	// Authors listed in Changelog.Maintainers or known bots are excluded.
	IncludeAuthors bool

	// IncludeSecurityMetadata includes CVE/GHSA/severity in security entries.
	IncludeSecurityMetadata bool

	// MarkBreakingChanges prefixes breaking changes with **BREAKING:**.
	MarkBreakingChanges bool

	// IncludeCompareLinks adds version comparison links at the bottom.
	IncludeCompareLinks bool

	// IncludeUnreleasedLink adds an [Unreleased] link comparing latest version to HEAD.
	// This lets users see what's been merged since the last release.
	IncludeUnreleasedLink bool

	// CompactMaintenanceReleases groups consecutive maintenance-only releases
	// (those with only dependencies, documentation, build, tests, internal changes)
	// into a single compact section like "## Versions 0.71.1 - 0.71.10 (Maintenance)".
	CompactMaintenanceReleases bool

	// MaxTier filters change types to include only those at or above this tier.
	// Default is TierOptional (include all).
	MaxTier changelog.Tier

	// Locale specifies the BCP 47 locale tag for output (e.g., "en", "fr", "de").
	// Default is "en" (English).
	Locale string

	// LocaleOverrides specifies a path to a JSON file with locale message overrides.
	// Only the messages specified in this file will be replaced; others use defaults.
	LocaleOverrides string

	// NotableOnly when true, only includes releases that are considered "notable"
	// according to the NotabilityPolicy. Non-notable releases (maintenance-only)
	// are excluded from the output entirely.
	NotableOnly bool

	// NotabilityPolicy defines which categories make a release notable.
	// If nil and NotableOnly is true, uses DefaultNotabilityPolicy().
	NotabilityPolicy *changelog.NotabilityPolicy

	// ExcludeCategories lists category names to omit entirely from the output
	// (e.g. "Dependencies"). Excluded categories produce no section at all.
	// This applies on top of MaxTier filtering.
	ExcludeCategories []string

	// CollapseCategories lists category names to render as a single summary
	// line (an entry count) instead of listing every entry. This preserves the
	// signal that maintenance occurred without the noise of a long list; the
	// full detail remains in the JSON source. ExcludeCategories takes
	// precedence: a category in both is omitted, not collapsed.
	CollapseCategories []string
}

Options controls how the Markdown is rendered.

func CoreOptions added in v0.4.0

func CoreOptions() Options

CoreOptions returns options for KACL-compliant core output.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default rendering options. Includes commit links and reference linking when repository URL is available. By default, only notable releases are included (NotableOnly: true).

func FullOptions

func FullOptions() Options

FullOptions returns options for maximum detail. Includes all releases (NotableOnly: false) and shows them expanded instead of grouping maintenance releases.

func MinimalOptions

func MinimalOptions() Options

MinimalOptions returns options for minimal output.

func OptionsFromConfig added in v0.4.0

func OptionsFromConfig(cfg Config) (Options, error)

OptionsFromConfig creates Options from a Config struct. It first applies the preset, then overrides MaxTier, Locale, LocaleOverrides, and notability settings if specified.

func OptionsFromPreset added in v0.4.0

func OptionsFromPreset(preset string) (Options, error)

OptionsFromPreset returns options for the given preset name. Valid presets are: default, minimal, full, core, standard.

func StandardOptions added in v0.4.0

func StandardOptions() Options

StandardOptions returns options including standard tier types.

func (Options) WithCollapseCategories added in v0.16.0

func (o Options) WithCollapseCategories(categories ...string) Options

WithCollapseCategories returns a copy of the options with the given category names appended to CollapseCategories.

func (Options) WithExcludeCategories added in v0.16.0

func (o Options) WithExcludeCategories(categories ...string) Options

WithExcludeCategories returns a copy of the options with the given category names appended to ExcludeCategories.

func (Options) WithExpandCategories added in v0.16.0

func (o Options) WithExpandCategories(categories ...string) Options

WithExpandCategories returns a copy of the options with the given category names removed from CollapseCategories, forcing them to render in full. This is how a caller overrides a preset's default collapse (e.g. Dependencies).

func (Options) WithLocale added in v0.10.0

func (o Options) WithLocale(locale string) Options

WithLocale returns a copy of the options with the Locale field set.

func (Options) WithLocaleOverrides added in v0.10.0

func (o Options) WithLocaleOverrides(path string) Options

WithLocaleOverrides returns a copy of the options with the LocaleOverrides field set.

func (Options) WithMaxTier added in v0.4.0

func (o Options) WithMaxTier(tier changelog.Tier) Options

WithMaxTier returns a copy of the options with the MaxTier field set.

func (Options) WithNotabilityPolicy added in v0.11.0

func (o Options) WithNotabilityPolicy(policy *changelog.NotabilityPolicy) Options

WithNotabilityPolicy returns a copy of the options with a custom NotabilityPolicy.

func (Options) WithNotableOnly added in v0.11.0

func (o Options) WithNotableOnly(enabled bool) Options

WithNotableOnly returns a copy of the options with NotableOnly set. When enabled, only releases with entries in notable categories are included.

Jump to

Keyboard shortcuts

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