With AI coding agents generating PRDs, architecture specs, skills, and design notes all day, my folders are full of .md files with Mermaid diagrams and math formulas.
I just wanted to click a .md file in Windows Explorer, press Alt+P, and see it rendered — without opening VS Code every time or installing all of PowerToys. Microsoft PowerToys previews Markdown in Explorer, but it skips Mermaid diagrams and math (and blocks images by default).
So I built MdPreview — a free, open-source (MIT), fully offline Windows Explorer preview handler that installs per-user with no admin rights and renders diagrams in under a second.
Here's what it does and the 3 non-obvious Windows + WebView2 lessons that made it fast and safe.
What It Renders (100% Offline)
-
Mermaid diagrams (flowcharts, sequence diagrams, etc.) and KaTeX math (
$...$/$$...$$) -
Syntax-highlighted code via
highlight.jswith auto-detection when no language tag is specified + Copy button -
GitHub-flavored Markdown: tables, task lists,
> [!NOTE]/[!WARNING]alerts, footnotes, emoji shortcodes (:rocket:→ 🚀), collapsible YAML front matter - Navigation: floating headings outline with scroll-spy, working in-document TOC links, and Ctrl+F find-in-page (via the CSS Custom Highlight API)
- Light / dark theme following Windows automatically
- Bonus: because it uses the standard Windows
IPreviewHandlerinterface, it also renders.mdattachments in classic desktop Outlook.
3 Engineering Lessons Along the Way
1. Why rewriting in Rust wouldn't have fixed the 9.9s cold start
Early on, the first Mermaid diagram took 9.9 seconds to render on a cold start. My first instinct was: "Is .NET or the Markdown parser slow? Should I rewrite this in Rust?"
Profiling proved that instinct completely wrong:
- Markdig parsed a real 27 KB PRD in 2.7 ms (and a 784 KB file in 65 ms).
- Almost the entire 9.9 seconds was Chromium booting and compiling Mermaid's 5.5 MB JavaScript bundle from scratch — because I had served all virtual assets with
Cache-Control: no-store.
Rewriting the host in Rust would still run WebView2 and still compile the exact same 5.5 MB JS bundle.
The actual fix was V8 bytecode caching:
- Serve the immutable bundled libraries (Mermaid, KaTeX, highlight.js) with cacheable headers +
ETagwhile keeping the HTML document itselfno-store. - Run a silent 2-pass off-screen warm-up during install (
Warmup.exe), because Chromium persists V8 bytecode to its on-disk Code Cache (~1.5 MB) on a script's second execution. - Start the WebView2 environment in parallel while Markdig parses the file.
Measured result (Windows 11, i9-13900H, WebView2 157):
| Scenario | Before | After |
|---|---|---|
| First diagram render after install | 9.9 s | 0.86 s |
Cold prevhost.exe (after browser exit / reboot) |
9.9 s | 0.5 – 0.75 s |
| Next file in the same pane (warm) | 0.25 – 0.7 s | 0.1 – 0.5 s |
| On-disk V8 Code Cache | 3 KB | ~1.5 MB (persisted) |
2. prevhost.exe ignores your HKCU integrity hints
Windows Explorer loads COM preview handlers (IPreviewHandler / IInitializeWithFile) into prevhost.exe at Low Integrity Level — even if you set DisableLowILProcessIsolation under HKCU.
If your handler tries to put its WebView2 user-data directory or logs inside %LOCALAPPDATA%, WebView2 silently fails to initialize in Explorer while passing all your standalone harness tests. Moving the WebView2 profile and log folder to %USERPROFILE%\AppData\LocalLow\MdPreview solved it cleanly — while keeping the entire installation per-user under HKCU and %LOCALAPPDATA%\Programs\MdPreview with zero administrator rights.
3. Strict offline CSP by default
Previewing random .md files shouldn't leak your IP or execute scripts. MdPreview serves the HTML page, bundled JS/CSS, and local images strictly from memory over a synthetic local origin (https://mdpreview.example/) with a strict Content-Security-Policy:
- Zero network access by default
- Scripts, iframes, and auto-redirects in hostile
.mdfiles never execute - Remote images are blocked and replaced with a clean placeholder (opt-in toggle included if you want them)
- External links open in your default browser only on an explicit click
Try It (Per-User, No Admin)
One-liner in PowerShell (inspect install-online.ps1 first if you prefer):
irm https://raw.githubusercontent.com/Zhanibek55/md-preview/main/install-online.ps1 | iex
Via Scoop:
scoop bucket add md-preview https://github.com/Zhanibek55/md-preview
scoop install md-preview
Or manually: grab MdPreview-0.1.0.0.zip (~4.4 MB) from GitHub Releases, unzip, and run Install.cmd. Then select any .md file in Explorer and hit Alt+P.
- GitHub (MIT): https://github.com/Zhanibek55/md-preview
- Optional download / tip jar (pay-what-you-want, $0+): https://payhip.com/b/yNw8e
What Should Explorer Preview Next?
Now that the IPreviewHandler + cached WebView2 pipeline works reliably offline, extending it to other developer and data formats is straightforward.
Which file types do you wish Windows Explorer rendered natively in the preview pane?
-
.parquet(schema + table preview + column stats) -
.ipynb(rendered Jupyter notebooks with charts, instead of raw JSON) -
.csv/.tsv(fast table view without launching Excel) -
.json/.yaml(collapsible tree + Ctrl+F)
Drop a comment — I'm genuinely curious which one hurts the most in your daily workflow!


Top comments (0)