catalogparse

package
v1.64.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package catalogparse parses a per-format catalog markdown document (the byte contents of one docs/catalog/<format>.md file) into the set of slug values whose Status is not "optional". It backs the per-format inventory_test.go regression guards that enforce S04's catalog-inclusion invariant. See S04 §Catalog inventory enforcement for the contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NonOptionalSlugs

func NonOptionalSlugs(markdown []byte) ([]string, error)

NonOptionalSlugs parses a catalog markdown document (the byte contents of one docs/catalog/<format>.md file) and returns the slug column values of every row whose Status is not "optional", across every catalog section. Malformed tables are rejected with an error rather than silently dropped.

On any malformed-table error the returned slice is nil: the result and the error are never both non-nil. The parser scans the input once, line by line; its live state is bounded by a single line (the section header cells and the current row), while the one-shot []byte→string conversion the scan iterates over is proportional to the whole input. It does not use backtracking-prone expressions on the input bytes, per docs/dev/go-secure-coding.md §Untrusted-input parsers.

The scan is purely structural: every line beginning with "|" is treated as a table row and every "## " line as a section start. Inside a table, a line that carries a pipe but does not begin with one is rejected as a row whose leading pipe is missing, rather than walked past — so a dropped pipe cannot silently drop a catalog row. It does not interpret fenced code blocks, so a catalog body must be tables and prose only, never a pipe-bearing fenced block — which the catalog files are.

Types

type MalformedTableError

type MalformedTableError struct {
	// Section is the catalog section heading text where the malformation
	// was found (without the leading "## "), or empty when the
	// malformation is not attributable to a single section.
	Section string
	// Reason is a human-readable description of why the table is
	// malformed. It is always a static string (or one interpolating only
	// integer column counts), never input-derived bytes.
	Reason string
}

MalformedTableError reports that a catalog section's markdown table is malformed and cannot be parsed. The four malformed shapes S04 §Catalog inventory enforcement enumerates are a row whose column count differs from its section header, a Status value outside the allowed set, a section table missing its header or separator row, and a Slug column that is empty or absent. Callers use errors.As.

func (*MalformedTableError) Error

func (e *MalformedTableError) Error() string

Error renders the malformation. Section is the only input-derived value it includes, and it is quoted with %q, so control bytes in a hostile catalog are escaped rather than injected into operator-facing output.

Jump to

Keyboard shortcuts

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