outlint-core
Validate the header structure (outline) of Markdown documents against a declarative schema.
This is the pure, IO-free core: it turns source text into normalized
values and diagnostics. It never touches the filesystem, the network, the
terminal, or the process exit status — that shell is the
outlint CLI crate. Callers supply the
schema text, the Markdown text, and any linked JSON Schema resources they
read themselves.
This is a 0.x release: expect breaking changes to the API, the schema
language, and the diagnostic set before 1.0. The normative specification is
spec/outlint-spec.md;
where the two disagree, the specification wins.
What it checks
- Outline structure — the section tree built from ATX and Setext headings, including skipped heading levels.
- Section rules — first-match-wins matchers (exact, glob, regex,
*),allow: falsedenials, andstrictscopes that reject unmatched headings. - Cardinality —
requiredandrepeat: "min..max"per rule, per scope. - Cross-section logic —
one_of,any_of,at_most_one,all_or_none,requires,conflicts, andorderedconstraints over rules addressed by id. - YAML frontmatter — presence policy and delegated validation of the
frontmatter mapping against an inline or linked JSON Schema (draft 2020-12).
Inline schemas are self-contained and permit fragment-only references;
linked schemas may span local files. Frontmatter also supports
fm.propositions in constraints:fm.keypresence andfm.key=valuetyped scalar equality under the YAML core schema, with dotted paths into nested mappings.
Diagnostics carry stable ids (missing-section, unexpected-section,
ordered, frontmatter-schema, …), document source anchors, and structural
schema-node addresses. Resolve a diagnostic's schema_node through
loaded.locations.nodes, then use the resulting SourceRange::source to find
the source text and label in loaded.sources.documents.
Usage
use ;
Output:
1:1 [missing-section] matched 0 sections, but at least 1 are required (expected Overview)
load_schema returns Result<LoadedSchema, InvalidSchema>; InvalidSchema
carries every schema error together with the source text needed to render it:
use load_schema;
if let Err = load_schema
For schemas whose frontmatter.schema points at an external JSON Schema file,
the caller owns the IO boundary. Use linked_frontmatter_schema_path to find
the root path, assign that file an absolute logical URI, then walk its local
reference graph with json_schema_external_references. The helper returns both
the lexical physical_uri to read and the $id-aware logical_uri under which
to register the contents. Ignore same-document references, deduplicate or
cycle-check reads, record read failures rather than dropping them, and place
every attempted resource in a LinkedJsonSchemaInput passed to
load_schema_with_resources. Core never retrieves remote references.
Related
outlint— the command-line tool built on this crate.- Outlint specification — the schema, validation, diagnostic, and CLI contracts.
MSRV
Rust 1.86.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your
option (MIT OR Apache-2.0).