Skip to main content

fabryk_content/
lib.rs

1//! Markdown parsing, frontmatter extraction, and content utilities.
2//!
3//! This crate provides generic content processing utilities used by all Fabryk
4//! domains. It has no domain-specific logic — each domain defines its own
5//! metadata types and uses these utilities for parsing.
6//!
7//! # Modules
8//!
9//! - [`markdown`]: Markdown parsing and frontmatter extraction
10//!   - [`markdown::frontmatter`]: YAML frontmatter extraction
11//!   - [`markdown::parser`]: Heading, paragraph, text extraction
12//!   - [`markdown::helpers`]: List and section extraction
13//!
14//! # Design Philosophy
15//!
16//! **Generic utilities, domain-specific types.** This crate provides:
17//!
18//! - YAML frontmatter extraction → returns `yaml_serde::Value`
19//! - Markdown structure parsing → returns strings and enums
20//! - Content helpers → returns strings and lists
21//!
22//! Domain crates (music-theory, math, etc.) define their own structs and
23//! deserialize from the generic types.
24//!
25//! # Example
26//!
27//! ```rust
28//! use fabryk_content::markdown::{extract_frontmatter, FrontmatterResult};
29//! use serde::Deserialize;
30//!
31//! // Your domain-specific frontmatter
32//! #[derive(Deserialize)]
33//! struct MyMeta {
34//!     title: String,
35//!     category: Option<String>,
36//! }
37//!
38//! let content = "---\ntitle: Hello\n---\n\nBody";
39//! let result = extract_frontmatter(content).unwrap();
40//! let meta: Option<MyMeta> = result.deserialize().unwrap();
41//! assert_eq!(meta.unwrap().title, "Hello");
42//! ```
43
44pub mod markdown;
45
46// Re-export commonly used types
47pub use markdown::{
48    FrontmatterResult, extract_all_list_items, extract_first_heading, extract_first_paragraph,
49    extract_frontmatter, extract_list_from_section, extract_section_content, extract_text_content,
50    normalize_id, parse_comma_list, parse_keyword_list, strip_frontmatter,
51};
52
53// Re-export HeadingLevel for convenience
54pub use pulldown_cmark::HeadingLevel;