Markdown is a lightweight markup language. To convert Markdown to HTML or PDF, a parser does not perform simple string replacement (Regex). It constructs an Abstract Syntax Tree (AST).
The Compilation Pipeline
- Lexing/Parsing: The engine reads the Markdown string and generates a hierarchical tree of nodes (e.g., Document -> Heading -> Text).
- Transformation: Plugins modify the AST (e.g., converting a standard link node into an embedded iframe).
- Generation: The engine walks the modified AST and emits the target format (HTML strings, or PDF layout commands).
CommonMark vs GFM
The core challenge in Markdown conversion is fragmentation. CommonMark is a strict specification, but GitHub Flavored Markdown (GFM) introduces tables, task lists, and strikethroughs. A robust conversion toolchain must explicitly state which specification its AST parser adheres to.