Documentation
¶
Overview ¶
Package tablefmt answers "what does the canonical aligned form of a pipe-table look like for these source lines?" Callers ask the package to format a string of markdown, to spot non-conforming tables in a parsed line list, or to rewrite the source bytes in place.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatLines ¶
FormatLines rewrites every table found in source with canonical formatting, preserving everything else. lines must be the result of splitting source on newlines (i.e. f.Lines from internal/lint).
func FormatString ¶
FormatString formats all markdown tables in s with the given padding and returns the result. Padding less than 0 falls back to 1 (one space of padding on each side of cell content). Uses the default spaced separator style; callers that need to choose a style call FormatStringWithConfig instead.
func FormatStringWithConfig ¶ added in v0.23.0
FormatStringWithConfig formats all markdown tables in s with cfg.
Types ¶
type Config ¶ added in v0.23.0
type Config struct {
Pad int
SeparatorStyle SeparatorStyle
}
Config controls how tables are formatted.
Pad is the number of spaces on each side of cell content. Values below 0 fall back to 1.
SeparatorStyle picks how the separator row is rendered: SeparatorSpaced writes `| --- | --- |` (the form spelled out by the GFM specification example), SeparatorCompact writes `|---|---|`. The zero value is SeparatorSpaced so a caller that builds a Config{Pad: 1} without touching the style field gets the spec-leaning default.
type SeparatorStyle ¶ added in v0.23.0
type SeparatorStyle int
SeparatorStyle selects the rendering of the separator row.
const ( // SeparatorSpaced writes `| --- | --- |`. Zero value so the // default-constructed Config picks this layout. SeparatorSpaced SeparatorStyle = iota // SeparatorCompact writes `|---|---|`. Dashes fill the cell area // with no whitespace around them. SeparatorCompact )
func ParseSeparatorStyle ¶ added in v0.23.0
func ParseSeparatorStyle(v any, ruleName string) (SeparatorStyle, error)
ParseSeparatorStyle converts a config value (typically a YAML scalar) to a SeparatorStyle, returning a rule-scoped error if v is not one of the supported string forms. ruleName is the rule's config key (e.g. "table-format", "catalog") and prefixes the error so multiple rules can share this helper without losing diagnostic context.