Lightweight Markdown Preview: Mermaid, D2 and Math in VS Code
A Markdown preview for VS Code. It draws D2 diagrams, Mermaid diagrams (GitHub and Azure DevOps syntax), LaTeX math and highlighted code beside your file. It follows your VS Code color theme, adds a collapsible outline sidebar, and collects no telemetry.

Features
| Feature |
What it does |
What you gain |
| D2 diagrams |
Draws every d2 fence through a renderer you choose |
Architecture diagrams stay text in your repository, so they diff in pull requests and AI agents can write them. See D2 diagrams. |
| Mermaid |
Draws backtick fences (GitHub) and ::: mermaid blocks (Azure DevOps) |
You check a diagram once and publish it to either platform. |
| LaTeX math |
Draws $...$ inline and $$...$$ block formulas with MathJax |
Prices such as "$5 and $10" and shell variables such as $HOME stay text. |
| Highlighted code |
Colors fenced code by language |
Code samples are easy to scan. |
| Outline sidebar |
Lists your headings in a collapsible panel that follows where you read |
You move through long documents quickly, and [intro](#intro) links scroll to their heading. |
| Color themes |
Follows your light, dark or high contrast VS Code theme and redraws when it changes |
Text, code and diagrams match your editor. |
| Script blocking |
Does not run scripts that a Markdown file contains |
Files from the internet, email or an unfamiliar repository cannot run code in the preview. |
| No telemetry |
Collects nothing and needs no account |
Your documents and diagrams stay with you. |
Install
- VS Code:
- Search for "Lightweight Markdown Preview" in the Extensions view, or for
KunalPathak.lightweight-markdown-preview.
- Forks such as Cursor and VSCodium:
First use
- Open a Markdown file.
- Select the eye icon in the editor title bar, or run Markdown: Show Lightweight Markdown Preview.
- Edit the file. The preview updates as you type and follows the file you switch to.
D2 diagrams
D2 is a text language for architecture diagrams, with nested containers, database tables, sequence diagrams and class diagrams. Text diagrams diff and review like code, and an AI agent can write and revise them. The preview draws each ```d2 fence as you type.


Set up a renderer
Start the renderer. The d2-renderer container keeps your diagram text on your machine:
docker run -d --name d2-renderer --platform linux/amd64 -p 8080:8080 ghcr.io/kanad13/d2-renderer:latest
Choose it. Run Markdown: Choose D2 Renderer and pick Local Docker container.

Write a d2 fence. The diagram appears in the preview.
| Piece |
What it does |
| D2 guide |
Setup, examples with their source and pictures, diagram options and troubleshooting. |
| d2-renderer |
The container that draws the diagrams. It includes the TALA layout engine, and a runbook deploys it to Google Cloud Run. |
| d2-architect |
An agent skill that adds a checked D2 diagram under every heading of a document, without changing your text. |
Mermaid, math and code
Mermaid draws from both platform syntaxes, so one source works on GitHub and in Azure DevOps. The sequence diagram below is drawn from a GitHub fence and from an Azure DevOps block.

Write inline math as $x_n$ and block math as $$ ... $$. Dollar signs that are not math stay text, so "costs $5 and $10" and echo $HOME render as written. Fenced code is highlighted.

Outline and themes
The ☰ button opens a collapsible outline that follows where you read. The preview uses your active color theme, whether light, dark or high contrast, and redraws when you change it.

| Dark |
Light |
 |
 |
Security and privacy
A Markdown file can contain HTML and scripts. The preview blocks them, so a file from the internet, an email or a cloned repository cannot run code in the preview.
| Risk |
What the preview does |
| A script inside a Markdown file |
Does not run it, whatever address it names. Harmless HTML such as <details> and <kbd> still works. |
A form or <base> tag that redirects the page |
Blocks form submits and <base> redirects. |
| A document that reports where you read it |
Sends no Referer header with image and font requests. |
| A repository that picks your D2 renderer |
Cannot: the renderer is a user setting. |
| A folder you have not trusted |
Previews work in VS Code Restricted Mode. |
| Usage tracking |
None: no telemetry, no analytics, no account. |
The preview makes these network requests and no others:
- Libraries: Mermaid, MathJax, its fonts, highlight.js and its theme, from jsDelivr at pinned versions.
- Images: the remote images your document names, fetched from their hosts.
- D2 diagrams: the diagram text, sent to the renderer you set.
The security policy explains how to report a vulnerability.
At a glance
| Measure |
Value |
| Package size |
About 100 KB |
| Runtime dependencies |
One: marked |
| Settings |
One: the D2 renderer URL |
Contribute
- Understand the design:
- Build and test:
- Work with agents and siblings:
- Follow changes:
Licensed under the MIT License.