Skip to main content

Module heading

Module heading 

Source
Expand description

Everything moss knows about a heading, in one place.

Headings used to be spread over four homes — heading.rs (the article title rule), heading_anchor.rs (the Obsidian slug algorithm), extract_headings.rs (the autocomplete walker), and a private collect_heading_text inside ast/parser.rs. They are not four subjects; they are four steps of one pipeline:

  inline nodes / parser events ──[text]──> plain text
                                             │
                                             ├─[anchor]──> the <hN id="…">
                                             └─[extract]─> autocomplete rows
  file path + frontmatter ───────[state]───> the auto-injected <h1>

The keystone invariant of the whole cluster is byte-identity: the slug extract reports, the id the renderer emits, and the raw-line slug the wikilink scanner computes in build/scan/scan.rs must agree character for character, or a [[Page#Heading]] link resolves to a fragment the page does not have. Spread across four files that identity was something tests had to keep re-checking; a math bug cluster hit three of the four homes independently in July 2026 precisely because nothing structural tied them together. Co-locating them makes the shared step (text) a single function instead of a coincidence.

Consolidation mandated by docs/reference/target/05-consolidation-map.md (row 36 and the F10 tiny-file merge list).

Re-exports§

pub use anchor::obsidian_heading_anchor;
pub use extract::extract_headings;
pub use extract::extract_headings_with_config;
pub use extract::HeadingInfo;
pub use state::hero_at_top_owns_title;
pub use state::compute;
pub use state::filename_text;
pub use state::filename_text_with_root;
pub use state::HeadingInputs;
pub use state::HeadingSource;
pub use state::HeadingState;

Modules§

anchor
Obsidian-compatible heading anchor generation.
extract
Pure extraction of a document’s headings (text + slug + level) for the editor’s [[Page#Heading]] autocomplete. Reuses parse() (which runs assign_heading_id_suffixes) so the returned slugs are byte-identical to the rendered <hN id="..."> attributes — the keystone invariant.
state
Article heading rule — single source of truth for the auto-injected <h1 class="moss-article-title"> and the editor’s pinned heading element.
text
“Inline content → plain text”, once.