Documentation
¶
Overview ¶
Package frontmatter is abcd's shared markdown-frontmatter line scanner. It is deliberately a line scanner, not a YAML parser: it reads only the top-level keys of the leading `---`…`---` block, first key wins, and pulls in zero dependencies. It exists so its consumers (internal/core/spec, internal/core/intent, and record-lint's top-level frontmatter checks) share ONE copy of this primitive rather than each keeping a private replica.
It is transport-agnostic: no stdout, no os.Exit, no filesystem access — the caller supplies the file's lines and decides what the fields mean.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fields ¶
Fields returns the top-level keys of the leading frontmatter block (the block between the first two `---` lines). Nested keys and list items are ignored, and the first occurrence of a key wins. An input whose first line is not `---` (or is empty) yields no fields. An unclosed block — a leading `---` with no closing `---` — is treated as no frontmatter (an empty map), so body prose is never harvested as fields.
func IsDelimiter ¶ added in v0.6.7
IsDelimiter reports whether a line is a frontmatter `---` delimiter.
This is the ONE delimiter rule. It is deliberately tolerant of trailing whitespace, and deliberately intolerant of everything else: `----`, `--- yaml` and an indented ` ---` are not delimiters, because leading whitespace survives the trim.
It does NOT trim a BOM, and must not. U+FEFF is a byte-order mark only at byte 0 of a file; anywhere else it is ZERO WIDTH NO-BREAK SPACE, an ordinary character, and a line spelled "\ufeff---" is a body line to every other reader. Trimming it here made Fields close a block early at such a line while intent's writer read on to the next bare `---` and inserted keys into the body — a lint-green record, a write that reports success, and a value invisible on reload (iss-2608270926036966). The BOM is a property of the FILE's first position, not of the character, so callers strip it from line 0 themselves (see TrimBOM) before asking this predicate anything.
Tolerance here is about the delimiter LINE, not about the block's content — capture's strictness about what is inside the block (duplicate top-level keys refused, indented lines refused, a restricted YAML subset) is a separate and deliberate policy, unaffected by this predicate.
Every reader of a record's bytes comes here rather than re-deriving the compare. capture kept a private byte-exact match (`--- ` was not a delimiter) while record-lint's ledger gate and the lifeboat graveyard read the same file through Fields, which trims: a trailing-space delimiter produced a lint-green issue file that every capture verb refused as malformed and that `abcd iss-N` reported as "not found in the issue ledger" while it sat in open/ — one format, two parsers, opposite verdicts, with the permissive one on the gate side (GitHub #338, the class iss-69 opened and left capture out of).
The line may still carry its end-of-line bytes: callers that split keeping ends (internal/core/capture) pass them in, and callers that split on "\n" do not, so both are trimmed.
func IsNull ¶
IsNull reports whether a frontmatter scalar is a YAML null.
The set is the YAML 1.2 core schema's, exactly: the empty value, "~", and the three spellings "null", "Null" and "NULL". It is deliberately NOT a case-insensitive compare — YAML does not accept "nUlL", and an EqualFold here would make abcd read records no YAML parser would agree with, which is worse than the miss it fixes (iss-287, reported as GitHub #290).
This is the ONE null predicate. internal/core/lint held a private copy that recognised only the lower-case spelling, so `impact: NULL` read as null in one gate and as a malformed impact in the other — the split-verdict shape that makes a record pass a lint and then fail the command that acts on it. Callers come here rather than re-deriving it.
The value must be the RAW scalar, before unquoting. Quoting is what separates a null from a string in YAML: bare null is a null, and "null" with its quotes is the three-character string. A caller that unquotes first destroys that distinction and cannot get it back.
func TrimBOM ¶
TrimBOM removes a single leading UTF-8 byte-order mark from s. The mark only ever appears as the file's very first bytes, so callers apply this to the first line before testing it for the opening `---`: a BOM sits invisibly ahead of the delimiter and, untrimmed, makes a well-formed record read as having no frontmatter — every frontmatter-keyed gate then passes it silently.
Types ¶
type Dup ¶ added in v0.6.7
Dup is a duplicated top-level key and the 1-based line of its SECOND (the offending) occurrence.
func Duplicates ¶ added in v0.6.7
Duplicates returns the top-level keys that appear more than once in the leading frontmatter block, one Dup per extra occurrence, in source order.
Fields keeps the FIRST occurrence and drops the rest silently — correct for a reader that wants one value, but it means a second `impact:` line hides the value a gate is armed to reject, and the strict ledger parser (internal/core/capture) refuses such a file outright (last-wins there would diverge from the first-occurrence rewrite setScalarField performs). A gate built on Fields calls Duplicates so it can refuse exactly what its consumer refuses (GitHub #357). The block-boundary contract is Fields': no leading `---` or no closing `---` yields nothing, so body prose is never scanned.