# DocEngine Architecture ## Overview DocEngine is a markdown rendering library that wraps pulldown-cmark (parsing) and ammonia (sanitization) behind a preset system. Each preset configures which markdown features are enabled and how aggressively the output is sanitized. ## Module Map ``` src/ lib.rs Crate root, re-exports, convenience functions render.rs Renderer struct (builder pattern, 4 presets, render/render_with_meta) sanitize.rs SanitizePreset enum (Permissive, Standard, Strict, Minimal) text.rs Text utilities (word_count, reading_time, extract_title, strip_first_heading) toc.rs Table of contents extraction and HTML rendering escape.rs HTML entity escaping for safe string interpolation code_spans.rs Code span/block byte range detection (used by mentions to skip code) directives.rs [directives] Alert/tabs blockquote post-processing doc_loader.rs [doc-loader] Load .md files from disk into in-memory page store frontmatter.rs [frontmatter] Parse +++delimited TOML frontmatter media_urls.rs [media-urls] CDN path rewriting for images, img-to-video conversion mentions.rs [mentions] @username extraction and resolution quotes.rs [quotes] [quote:UUID:HASH] post-processing for forum attribution ``` ## Design Decisions ### Presets over configuration Rather than exposing every pulldown-cmark option, DocEngine provides named presets that bundle markdown features with sanitization levels. This prevents misconfiguration -- you can't accidentally enable raw HTML without appropriate sanitization. Custom configurations are still possible via the builder pattern (`Renderer::permissive().with_strip_images(true)`). ### Two-phase rendering Rendering happens in two phases: 1. **pulldown-cmark** parses markdown to HTML events, with optional filtering (strip images, strip raw HTML, neutralize dangerous URL schemes) 2. **ammonia** sanitizes the resulting HTML string This means even the permissive preset strips `