Skip to main content

Module frontmatter_values

Module frontmatter_values 

Source
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§

FrontMatterLink
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 filenames myapp(1).md), so they must not act as mid-token boundaries, only as leading/trailing punctuation to peel off prose wrapping such as See (docs/a.md) here..

Functions§

field_map
The lowercased top-level frontmatter key owning each line, indexed by line number. None where 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_start is a quoted scalar: the character immediately preceding value_start is a quote. Call this with the span start returned by value_span, which always lands just past the opening quote for quoted values. The raw value_offset does not carry that guarantee: its helper kv_value_offset only 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::MAX if 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. None when the line carries no checkable value, including an empty quoted value ('').