Expand description
moss-core is the pure-Rust content engine behind moss, a desktop publishing app. It owns every transformation that turns a folder of markdown into a website: parsing, wikilink resolution, HTML rendering, frontmatter typing, and schema validation.
Everything is data in, data out — strings and structs in; parsed ASTs, diagnostics, and rendered HTML out. Zero I/O, zero async, no global state. The filesystem, the network, and the async runtime all live one layer up, in moss’s host; this crate never touches them. That makes it deterministic, trivially unit-testable, and embeddable in any Rust program — not just moss.
§How it’s laid out
The modules cluster into four areas, plus the contract surface:
- Parse & render —
astturns markdown into a typed tree (overpulldown-cmark) and renders it back to HTML through interceptable hooks;renderemits media HTML (image/video/audio/iframe/pdf) for embeds. - Frontmatter & schema —
frontmatterparses YAML while preserving the body byte-for-byte;frontmatter_typedis the canonicalFrontMatterstruct;schema_fieldsis the single source of truth for built-in fields;validationproduces LSP-style diagnostics against a schema. - Links & content model —
resolveis the one place wikilinks and embeds ([[...]]) become ordinary markdown links;content_graphdoes the Obsidian-style fuzzy path matching underneath. - Utilities — small stateless helpers the editor and build share:
slug,date,sort,home,page_kind, andextract_headings.
Plus contract: the design surface (W3C design tokens + the moss-* HTML
class table) that theme authors and codegen depend on.
§Getting started
Every entry point is a free function — pick the module and call it:
use moss_core::frontmatter;
let raw = "---\ntitle: Hello\n---\n\nBody text";
let doc = frontmatter::parse(raw);
assert_eq!(doc.frontmatter.get("title").and_then(|v| v.as_str()), Some("Hello"));
assert_eq!(doc.body.trim(), "Body text"); // body preserved verbatimFrom there: ast for the body tree, resolve to flatten wikilinks,
validation to lint frontmatter, and extract_headings for anchors.
§Guarantees
Total functions: bad input degrades to a best-effort value, never an Err or
a panic. No unsafe (#![forbid(unsafe_code)]). Schema problems are reported
out-of-band as validation diagnostics, not return values.
moss ships this crate in a host built with panic = "abort" (release
profile), so a panic on user input crashes the whole desktop app (see the
date.rs fix for the
editor-mount panic on Chinese filenames). The lint attributes below enforce
the panic-free contract — deny(clippy::string_slice) plus
deny(clippy::unwrap_used/expect_used) outside tests — each with a per-site
escape-hatch rule.
Re-exports§
pub use extract_headings::extract_headings;pub use extract_headings::HeadingInfo;pub use page_kind::PageKind;pub use resolved::Resolved;pub use resolved::ResolvedOrigin;
Modules§
- asset_
paths - Pure URL/path transform helpers — no filesystem access, no env lookups. Used by moss-core’s render functions (see crate::render::*) and by upstream src-tauri call sites.
- asset_
snapshot - Pre-fetched asset metadata available to Stage 1 + Stage 2.
- ast
- Typed body AST.
- content_
graph - In-memory index of content files, headings, and block IDs.
- contract
- moss HTML/CSS contract surface.
- csv_
table - Pure CSV/TSV → HTML table renderer.
- date
- Publish-date resolution for moss content.
- extract_
headings - Pure extraction of a document’s headings (text + slug + level) for the
editor’s
[[Page#Heading]]autocomplete. Reusesparse()(which runsassign_heading_id_suffixes) so the returned slugs are byte-identical to the rendered<hN id="...">attributes — the keystone invariant. - frontmatter
- YAML frontmatter parsing with body preservation.
- frontmatter_
typed - Typed frontmatter structs for the build pipeline.
- frontmatter_
union - Normalization for union-typed frontmatter fields (
children,series). - heading
- Article heading rule — single source of truth for the auto-injected
<h1 class="moss-article-title">and the editor’s pinned heading element. - heading_
anchor - Obsidian-compatible heading anchor generation.
- home
- Home file detection for the moss content model.
- link_
candidates - Link resolution candidate generation.
- link_
completions - Pure ranker for wikilink autocomplete completions.
- media
- Unified media reference resolution and display attributes.
- page_
kind - Classification of moss page/source-file kinds.
- render
- HTML synthesizers for moss-emitted markdown content.
- resolve
- Centralized link resolution — ALL wikilink handling (body AND frontmatter) happens here.
- resolved
- A value paired with its origin. Lets downstream consumers decide whether to honor the value as author intent (explicit) or override it with an inferred default (auto-detected).
- schema
- Content model types driven by the schema.
- schema_
fields - Builtin frontmatter field definitions.
- shortcode_
tokens - Tokenizer for shortcode opening, closing, and divider lines.
- slug
- URL-safe slug generation for moss-core.
- sort
- Folder-listing sort: types and inference cascade.
- validation
- Schema-driven frontmatter validation.