# dawnsws/md2png architecture

> Architecture diagram of the GitHub repository dawnsws/md2png, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dawnsws/md2png
- Repository: https://github.com/dawnsws/md2png

## Overview

md2png is a command-line Markdown-to-PNG renderer. Its main workflow accepts a Markdown file or clipboard text, converts Markdown (including tables, images, code, and math) to Typst markup, compiles and rasterizes pages, then writes uniquely named PNG files. The internal rendering layer supplies fonts and safely resolves document-relative resources. The README is empty, so capabilities and wiring here reflect the sampled source; Windows clipboard support is conditional.

Main entry points: [`src/render.rs`](https://github.com/dawnsws/md2png/blob/main/src/render.rs) (Compile and export), [`src/main.rs`](https://github.com/dawnsws/md2png/blob/main/src/main.rs) (CLI workflow), [`src/markdown.rs`](https://github.com/dawnsws/md2png/blob/main/src/markdown.rs) (Markdown conversion), [`src/input.rs`](https://github.com/dawnsws/md2png/blob/main/src/input.rs) (Input loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input"]
  node_main["CLI workflow<br/>[main.rs]"]
  node_input["Input loading<br/>[input.rs]"]
end

subgraph group_convert["Conversion"]
  node_markdown["Markdown conversion<br/>[markdown.rs]"]
  node_preamble["Typst preamble<br/>[preamble.typ]"]
  node_cmark["Markdown parser"]
  node_math["Math converter"]
end

subgraph group_render["Rendering"]
  node_render["Compile and export<br/>[render.rs]"]
  node_world["Typst world<br/>[world.rs]"]
  node_typst["Typst compiler"]
  node_raster["Page rasterizer"]
end

subgraph group_output["Output"]
  node_writer["PNG file writer<br/>[output.rs]"]
end

node_user(("User"))
node_file["Markdown file"]
node_clipboard["System clipboard"]
node_filesystem["Local filesystem"]
node_fonts["Typst font assets"]
node_png["PNG files"]

node_user -->|"invokes"| node_main
node_file -->|"reads"| node_input
node_clipboard -.->|"provides text"| node_input
node_filesystem -->|"reads file"| node_input
node_main -->|"parses and loads"| node_input
node_input -->|"returns content"| node_main
node_main -->|"converts content"| node_markdown
node_markdown -->|"parses Markdown"| node_cmark
node_markdown -->|"converts formulas"| node_math
node_preamble -->|"included in markup"| node_markdown
node_markdown -->|"returns markup"| node_render
node_main -->|"renders markup"| node_render
node_render -->|"creates resource world"| node_world
node_render -->|"compiles document"| node_typst
node_typst -->|"requests sources and files"| node_world
node_world -->|"loads font data"| node_fonts
node_world -->|"reads local resources"| node_filesystem
node_render -->|"rasterizes pages"| node_raster
node_render -->|"saves encoded PNG"| node_writer
node_writer -->|"creates unique files"| node_filesystem
node_filesystem -->|"stores"| node_png
node_render -->|"returns output paths"| node_main

click node_main "https://github.com/dawnsws/md2png/blob/main/src/main.rs"
click node_input "https://github.com/dawnsws/md2png/blob/main/src/input.rs"
click node_markdown "https://github.com/dawnsws/md2png/blob/main/src/markdown.rs"
click node_preamble "https://github.com/dawnsws/md2png/blob/main/src/preamble.typ"
click node_render "https://github.com/dawnsws/md2png/blob/main/src/render.rs"
click node_world "https://github.com/dawnsws/md2png/blob/main/src/world.rs"
click node_writer "https://github.com/dawnsws/md2png/blob/main/src/output.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_input,node_user toneBlue
class node_markdown,node_preamble,node_cmark,node_math toneAmber
class node_render,node_world,node_typst,node_raster toneMint
class node_writer toneRose
class node_file,node_clipboard,node_filesystem,node_fonts,node_png toneIndigo
```

## Components

### Input

- [CLI workflow](https://github.com/dawnsws/md2png/blob/main/src/main.rs): `src/main.rs`
- [Input loading](https://github.com/dawnsws/md2png/blob/main/src/input.rs): `src/input.rs`

### Conversion

- [Markdown conversion](https://github.com/dawnsws/md2png/blob/main/src/markdown.rs): `src/markdown.rs`
- [Typst preamble](https://github.com/dawnsws/md2png/blob/main/src/preamble.typ): `src/preamble.typ`
- **Markdown parser**
- **Math converter**

### Rendering

- [Compile and export](https://github.com/dawnsws/md2png/blob/main/src/render.rs): `src/render.rs`
- [Typst world](https://github.com/dawnsws/md2png/blob/main/src/world.rs): `src/world.rs`
- **Typst compiler**
- **Page rasterizer**

### Output

- [PNG file writer](https://github.com/dawnsws/md2png/blob/main/src/output.rs): `src/output.rs`

### Other components

- **User**
- **Markdown file**
- **System clipboard**
- **Local filesystem**
- **Typst font assets**
- **PNG files**

## Connections

- User → CLI workflow: invokes
- Markdown file → Input loading: reads
- System clipboard → Input loading: provides text
- Local filesystem → Input loading: reads file
- CLI workflow → Input loading: parses and loads
- Input loading → CLI workflow: returns content
- CLI workflow → Markdown conversion: converts content
- Markdown conversion → Markdown parser: parses Markdown
- Markdown conversion → Math converter: converts formulas
- Typst preamble → Markdown conversion: included in markup
- Markdown conversion → Compile and export: returns markup
- CLI workflow → Compile and export: renders markup
- Compile and export → Typst world: creates resource world
- Compile and export → Typst compiler: compiles document
- Typst compiler → Typst world: requests sources and files
- Typst world → Typst font assets: loads font data
- Typst world → Local filesystem: reads local resources
- Compile and export → Page rasterizer: rasterizes pages
- Compile and export → PNG file writer: saves encoded PNG
- PNG file writer → Local filesystem: creates unique files
- Local filesystem → PNG files: stores
- Compile and export → CLI workflow: returns output paths
