Expand description
Open Knowledge Format (OKF) support shared across the suite.
OKF v0.1
is a minimal standard for knowledge corpora: a directory tree of Markdown
concept files, each carrying a leading YAML frontmatter block (one
required field, type; recommended title/description/resource/tags/
timestamp), plus reserved index.md (a directory listing) and log.md (a
change history). Cross-links are ordinary Markdown links, either
bundle-relative (/tables/customers.md) or document-relative.
This module is the single home for the format: frontmatter detection and
field extraction (parse), reserved-file recognition (is_reserved),
cross-link extraction (links), bundle conformance (conformance) and
broken-link detection (broken_links). It is reused by ct-okf, by the
OKF-awareness added to ct-search/ct-tree/ct-view/ct-outline, and by
the okf built-in check (check).
Conformance is deliberately permissive (per the spec): a non-reserved .md
conforms when it has parseable frontmatter carrying a non-empty type;
unknown keys, unknown types, and broken links are tolerated, never fatal.
Structs§
- Finding
- A per-file conformance finding for a bundle.
- Frontmatter
- The recognised frontmatter fields, extracted from a concept’s YAML block.
Unknown keys are preserved in
extra, as the spec requires consumers to tolerate and round-trip them. - Link
- A Markdown cross-link found in a concept body.
- Parsed
- A concept’s parsed frontmatter and where it sits in the file.
Constants§
- RESERVED
- Reserved file names with defined structural roles; never concept documents.
Functions§
- broken_
links - Find bundle cross-links whose target file is missing. Bundle-relative
(
/…) targets resolve againstbase; document-relative targets resolve against the linking file’s directory. Any fragment (#…) is dropped before resolution. External URLs are ignored bylinksand never appear here. - build_
concept - Build a new concept’s file text: a frontmatter block (a non-empty
typeis required by OKF) followed by the body, defaulting to a single# titleheading when no body is given. - check
- Run an
okfbuilt-in check: walk the bundle underroot/--baseand assert every non-reserved.mdconforms (parseable frontmatter with a non-emptytype); with--strict, also assert no broken bundle cross-links. Returns the probe outcome, a one-line reason, and a violation report. Argument and walk errors areProbeOutcome::Broken. - check_
grammar - The
okfcheck’s introspected grammar (see [crate::deps::grammar]). - conformance
- Walk a bundle and judge each
.mdfile’s conformance. - fm_
to_ json - Render a
Frontmatteras a JSON object — only fields that are present appear; unknown keys fromextraare included verbatim. Shared soct-okfand the OKF-aware tools emit metadata the same way. - is_
reserved - Whether
file_nameis an OKF reserved file (index.md/log.md). - links
- Extract Markdown
[text](target)cross-links frombody, skipping external URLs (http(s)://,mailto:) and bare anchors (#…). The kind of relationship is conveyed by prose, not syntax, so links are untyped edges. - log_
entry - Prepend a dated, labelled entry to a
log.md’s existing text, merging into the same-day section when it is already on top (newest first). - md_
selector - Build a
.md-restrictedwalk::Selectorunderbase, optionally narrowed by anamepattern set. Shared by the tool and the built-in check so they select concepts identically. - parse
- Parse a concept’s leading frontmatter, or
Nonewhen the text does not open with a---fence (the only frontmatter form OKF defines). - render_
index - Render an
index.mdbody from(file, title, description)entries. - set_
field - Set or update a top-level scalar frontmatter
fieldon a concept’stext, preserving every other byte. Returns the new text and whether an existing key was replaced (falsemeans a new key was appended before the closing fence). Errors when the text has no frontmatter to edit. - today_
utc - Today’s date as
YYYY-MM-DD(UTC), via Howard Hinnant’s civil-from-days. Shared solog.mdentries and timestamps are stamped consistently. - yaml_
scalar - Quote a frontmatter scalar value if it would not be a safe bare YAML scalar.
Shared by the authoring verbs and the
--scriptengine so a value written by either path round-trips identically.