convention

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package convention owns the convention and flavor data shapes independent of any rule. A convention pairs a Markdown flavor with a table of rule presets; the config loader consults this package at load time so a top-level `convention:` selection becomes a base layer beneath the user's own rule config. Rule packages (notably internal/rules/markdownflavor) consume these data shapes — they do not own them — which keeps internal/config from importing a rule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns the sorted list of built-in convention names.

Types

type Convention

type Convention struct {
	// Name is the lowercase identifier used in YAML config.
	Name string
	// Flavor is the Markdown flavor MDS034 should validate against.
	Flavor Flavor
	// Rules maps rule name (e.g. "no-inline-html") to the preset that
	// the convention applies for that rule.
	Rules map[string]RulePreset
}

Convention is an opinionated bundle that pairs a Markdown flavor with a table of rule presets. Selecting a convention in config applies both: MDS034 runs against the named flavor, and the named rule presets are applied as a base layer beneath the user's own rule config.

Conventions are codebase-versioned. The Rules table may reference rules that are not yet registered (presets for upcoming MDS04x rules ship alongside the convention so that adding the rule does not require updating every consumer's config). The config loader stores those presets in the merged config; the rule engine iterates the registered rules at check time and silently skips any preset that does not name one. The settings activate automatically once the rule lands and registers.

func Lookup

func Lookup(name string, userConventions map[string]Convention) (Convention, error)

Lookup returns the convention with the given name. It first checks userConventions (user-defined entries from .mdsmith.yml), then the built-in table. Returns a deep copy so callers can mutate the result without corrupting the shared tables. Error lists both sets of valid names when neither matches.

userConventions may be nil; a nil map is treated as empty.

type Flavor

type Flavor int

Flavor identifies a target Markdown flavor.

const (
	FlavorCommonMark Flavor
	FlavorGFM
	FlavorGoldmark
	// FlavorAny accepts every tracked feature. Useful when the
	// document is destined for an unknown or permissive renderer and
	// the user wants to disable flavor reporting without disabling
	// the rule.
	FlavorAny
	// FlavorPandoc is Pandoc's default markdown dialect. Accepts
	// GFM's four features plus footnotes, definition lists, heading
	// IDs, superscript, subscript, math block, and inline math;
	// rejects abbreviations (a non-default Pandoc extension).
	FlavorPandoc
	// FlavorPHPExtra is PHP Markdown Extra. Accepts tables,
	// footnotes, definition lists, heading IDs, and abbreviations;
	// rejects GFM's task lists, strikethrough, bare-URL autolinks,
	// and every math / sub/superscript feature.
	FlavorPHPExtra
	// FlavorMultiMarkdown extends PHP Markdown Extra with math
	// block and inline math. Like PHP Extra, rejects GFM task lists,
	// strikethrough, bare-URL autolinks, and sub/superscript.
	FlavorMultiMarkdown
	// FlavorMyST is the MyST flavor used by the Sphinx documentation
	// toolchain. Accepts tables, strikethrough, footnotes,
	// definition lists, heading IDs, math block, and inline math;
	// rejects GFM task lists, bare-URL autolinks, sub/superscript,
	// and abbreviations.
	FlavorMyST
)

Flavor constants. The zero value is intentionally invalid so that unparsed settings are caught.

func ParseFlavor

func ParseFlavor(s string) (Flavor, bool)

ParseFlavor converts a config string into a Flavor. The match is case-sensitive to reject typos like "GFM" that would otherwise silently validate against the wrong flavor.

func (Flavor) IsValid

func (f Flavor) IsValid() bool

IsValid reports whether f names a recognised flavor. The zero value (reserved for "unparsed/unset") and any out-of-range integer cast to Flavor both return false. Implemented in terms of String so the two stay in lock-step: every recognised flavor has a name, and adding a new constant only requires updating the switch in String.

func (Flavor) String

func (f Flavor) String() string

String returns the canonical lowercase name of the flavor.

type RulePreset

type RulePreset struct {
	Enabled  bool
	Settings map[string]any
}

RulePreset is a convention's preset for a single rule. It mirrors the shape of config.RuleCfg without depending on the config package, so this package can declare convention tables without the import cycle that would otherwise result.

Jump to

Keyboard shortcuts

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