How swiftlang/swift-markdown works
Main Components
a) Parser Layer:
• Entry point through Document parser
• CommonMarkConverter (uses cmark-gfm)
• To BlockDirectiveParser and other parsing components
b) Core Data Structure Layer:
• Document as the root node
• Markup hierarchy with different node types:
• Block Nodes (BlockQuote, Lists, CodeBlock, etc.)
• Inline Nodes (Link, Emphasis, Text, etc.)
• Table-related nodes
• Custom nodes
c) Processing Layer:
• Visitors (MarkupVisitor)
• Walkers (MarkupWalker)
• Rewriters (MarkupRewriter)
• Formatters (HTMLFormatter, MarkupFormatter)
d) Utility Layer:
• Source location tracking
• Atomic operations
• Range management
[Input: String/URL] → [Parser Layer] → [Core Data Structure Layer] → [Processing Layer] → [Output]
• ↑↓
• [Utility Layer]
Important Relationships to Highlight
• How the Document parser creates the initial markup tree
• Hierarchical relationship between different types of nodes
• Demonstrate how Visitors/Walkers traverse the markup tree
• How Rewriters can modify the structure while maintaining immutability
Key Technical Aspects to Emphasize
• Copy-on-write value types for the markup tree
• Thread-safety mechanisms
• Immutable/persistent data structures
• Integration with cmark-gfm for parsing
Implementation Details
[Document Parser]
• ↓
[Markup Tree]
• [Block Nodes]
• Container Blocks (BlockQuote, Lists)
• Leaf Blocks (CodeBlock, Heading)
• Tables
• [Inline Nodes]
• Containers (Emphasis, Link)
• Leaves (Text, InlineCode)
• [Processing]
• Visitors
• Walkers
• Rewriters