Skip to main content

normalize_document

Function normalize_document 

Source
pub fn normalize_document(doc: Document) -> Result<Document, ParseError>
Expand description

Normalizes a typed crate::document::Document by applying all field-level normalizations.

This is the primary entry point for normalizing documents after parsing. It ensures consistent processing regardless of how the document was created.

§Normalization Steps

  1. Unicode NFC normalization — Frontmatter field names are normalized to NFC form.
  2. Bidi stripping — Invisible bidirectional control characters are removed from body regions (each Card::body). YAML field values in every Card::frontmatter pass through verbatim (spec §7).
  3. HTML comment fence fixing — Trailing text after --> is preserved in body regions only.

Double chevrons (<< and >>) are passed through unchanged without conversion.

§Idempotency

This function is idempotent — calling it multiple times produces the same result.

§Example

use quillmark_core::{Document, normalize::normalize_document};

let markdown = "---\nQUILL: my_quill\ntitle: Example\n---\n\nBody with <<placeholder>>";
let doc = Document::from_markdown(markdown).unwrap();
let normalized = normalize_document(doc).unwrap();