Lightweight Markdown Preview, One Year Later: D2, Mermaid, and Math in VS Code
A year ago, I released Lightweight Markdown Preview, my first VS Code extension. Over the following year, I added D2 diagrams, an outline of your headings, support for every VS Code color theme, and the security work from my security check-up.
The extension is free and open source. It shows a live preview beside your Markdown file with D2 and Mermaid diagrams, math formulas, and highlighted code. This post shows what the preview does today and where to get it.
Navigate this post
What it does
Open a Markdown file and click the eye icon at the top of the editor. The preview opens beside your file and updates as you type. When you switch to another Markdown file, the preview switches with you.

-
D2 diagrams
Architecture diagrams written in D2 appear in the preview as you type. -
Mermaid diagrams
Mermaid, another text format for diagrams, works in both the GitHub and the Azure DevOps style. -
Math and code
LaTeX formulas display as formatted math, and code is colored by language. -
Outline sidebar
A panel lists your headings and follows where you read.
Architecture diagrams with D2
D2 is a text language for architecture diagrams. It draws nested containers, database tables, and sequence diagrams. Because each diagram is text in your repository, you review a change to a diagram the same way you review a change to code.

D2 diagrams need a renderer, the program that turns D2 text into a picture. You pick one once: d2-renderer, a small container I also built, running on your own computer; the public Kroki service; or a server of your own. With d2-renderer running locally, your diagram text never leaves your computer.
Mermaid, math, and code
Mermaid diagrams written for GitHub and Mermaid diagrams written for Azure DevOps both work, even in the same file.

Math uses the usual $...$ and $$...$$ markers. Dollar amounts such as "$5 and $10" and shell variables such as $HOME display as ordinary text. Code blocks are colored by language.

Outline and themes
The ☰ button opens an outline of your headings. The outline follows where you read, and links to headings scroll the preview to the right place.

The preview uses your VS Code color theme, whether light, dark, or high contrast, and redraws when you change it.

Privacy and security
- Document scripts blocked: the preview does not run scripts that a Markdown file contains, so a file from the internet, an email, or an unfamiliar repository cannot run code in the preview.
- No tracking: the extension collects no data and needs no account.
- Known network requests: the preview downloads its libraries from jsDelivr at fixed versions, loads the images your document names, and sends D2 diagram text to the renderer you choose.
- Works in untrusted folders: the preview runs in VS Code's Restricted Mode, which VS Code uses for folders you have not marked as trusted.
Get started
Lightweight Markdown Preview is available for VS Code on the Visual Studio Marketplace, and for editors such as VSCodium and Cursor on Open VSX. The source code and documentation are on GitHub.
- Lightweight Markdown Preview on the Visual Studio Marketplace
- Lightweight Markdown Preview on Open VSX
- Lightweight Markdown Preview source code and documentation on GitHub
Conclusion
A year on, Lightweight Markdown Preview shows D2 and Mermaid diagrams, math, and code beside your Markdown, with an outline for long documents. Install it from the Marketplace or Open VSX, and find the source and documentation on GitHub.
References and further reading
Open the complete reference catalog
Primary Sources
- Lightweight Markdown Preview on the Visual Studio Marketplace
- Lightweight Markdown Preview on Open VSX
- Lightweight Markdown Preview repository on GitHub
- D2 diagram language
- Mermaid diagram documentation
Related Site Guides
- Built My First VS Code Extension: Lightweight Markdown Preview - The first release
- d2-renderer - The container that draws D2 diagrams on your own machine
- Keeping My Projects on Current Versions: A Security Check-Up - The security work behind this release
- NotionDown - A Visual Markdown Editor for VS Code - Write Markdown on one page that looks like the final document