DEV Community

Cover image for How I Rendered Mermaid & Math Markdown in Windows Explorer in 0.86s (No PowerToys, No Admin)
Zhanibek Nugmanov
Zhanibek Nugmanov

Posted on

How I Rendered Mermaid & Math Markdown in Windows Explorer in 0.86s (No PowerToys, No Admin)

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.

MdPreview rendering Markdown and diagrams in Windows Explorer

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.js with 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 IPreviewHandler interface, it also renders .md attachments in classic desktop Outlook.

Dark theme with outline, syntax highlighting, and blocked remote image placeholder


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:

  1. Serve the immutable bundled libraries (Mermaid, KaTeX, highlight.js) with cacheable headers + ETag while keeping the HTML document itself no-store.
  2. 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.
  3. 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 .md files 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
Enter fullscreen mode Exit fullscreen mode

Via Scoop:

scoop bucket add md-preview https://github.com/Zhanibek55/md-preview
scoop install md-preview
Enter fullscreen mode Exit fullscreen mode

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.


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)