Expand description
Reading values out of a document’s frontmatter.
Frontmatter is YAML, TOML or JSON rather than Markdown, so the rules that look at it need answers Markdown parsing cannot give: where the checkable value on a line starts and ends, which top-level key owns a line, and whether a value reads as a link destination. This module is the single place those answers are computed, so every rule reading frontmatter agrees about what it contains.
Parsing is deliberately line-based and heuristic rather than a full YAML or TOML parse: rules need byte spans inside the original line to report and fix at, and a real parser hands back reconstructed values with no position.
Structs§
- Front
Matter Link - A frontmatter value that reads as a link destination.
Constants§
- PATH_
TOKEN_ WRAPPERS - Delimiters that wrap a token from the outside (quotes, brackets, parens,
angle brackets) rather than appearing inside a path. Used only by the
edge-trimming pass: these characters legitimately occur inside real paths
(Next.js route groups
(marketing)/, dynamic segments[slug], disambiguated filenamesmyapp(1).md), so they must not act as mid-token boundaries, only as leading/trailing punctuation to peel off prose wrapping such asSee (docs/a.md) here..
Functions§
- field_
map - The lowercased top-level frontmatter key owning each line, indexed by line
number.
Nonewhere no owner is determinable, which leaves the line checked. - is_
link_ destination - Whether a frontmatter value reads as a link destination rather than prose.
- link_
destinations - Every frontmatter value that reads as a link destination, in document order, each attributed to the top-level key that owns it.
- token_
bounds - Bounds of the whitespace-delimited token containing
pos, clamped to[value_start, value_end). The clamp is what keeps this search inside a single frontmatter value: it can never walk past the value’s own boundaries, so it can never wander into Markdown link syntax on the same line (frontmatter has none) or onto a neighboring line. - trim_
token_ bounds - Strip wrapping delimiters, then trailing sentence punctuation, repeating both
passes until a full pass leaves the bounds unchanged. Punctuation removal can
expose a wrapper underneath it (
"docs/myapp.md",sheds the comma to reveal a trailing quote), so a single sequential pass is not enough to reach a stable result. - value_
is_ quoted - Whether the frontmatter value starting at
value_startis a quoted scalar: the character immediately precedingvalue_startis a quote. Call this with the span start returned byvalue_span, which always lands just past the opening quote for quoted values. The rawvalue_offsetdoes not carry that guarantee: its helperkv_value_offsetonly skips the opening quote when the whole trimmed remainder of the line starts and ends with the same quote character, so a trailing comment or an unterminated quote leaves the offset pointing AT the quote instead of past it. - value_
offset - For a frontmatter line, the byte offset where the checkable value portion
starts. Returns
usize::MAXif the entire line should be skipped (frontmatter delimiters, key-only lines, YAML comments, flow constructs). - value_
span - Byte span of the semantic value on a frontmatter line: the checkable content
with a trailing comment excluded. For a quoted scalar the span ends at the
closing quote (or the trimmed end of line if the quote is unterminated), so
#and spaces inside it are literal, and the quote characters themselves are never part of the span.Nonewhen the line carries no checkable value, including an empty quoted value ('').