markdown-viewer
Render a Markdown file with GitHub styling and view it in your browser, with live reload while you edit. A small, fast, offline alternative to grip and Marked 2.
For a tour of every feature, run:
Features
Rendering
- GitHub's look, in light, dark, or following your OS setting. Switch any time with t.
- Built-in styles:
github(default),wide(full window width),book(serif type, for long reading) andcompact. Add your own CSS with--css. - GitHub Flavored Markdown:
- Headings with link anchors (hover a heading for its link icon).
- Bold, italic and strikethrough.
- Tables with column alignment.
- Task lists.
- Autolinked URLs and email addresses.
- Footnotes.
- Emoji shortcodes such as
:rocket:.
- GitHub alerts, with GitHub's icons:
> [!NOTE],[!TIP],[!IMPORTANT],[!WARNING]and[!CAUTION]. - Syntax highlighting for fenced code blocks, done when the page is built (no JavaScript), with copy and wrap buttons on each block.
- Code block extras, set after the language (GitHub ignores them):
```rust title="main.rs" {3-5} showLineNumbersadds a file-name title, highlights lines 3 to 5 and numbers the lines.--line-numbersnumbers every block. - A
[TOC]line, or<!-- TOC -->, becomes a table of contents built from the headings (<!-- TOC max2 -->for two levels). - Theme-aware images:
#gh-light-mode-onlyand#gh-dark-mode-onlyimage URLs show only in that theme, as on GitHub. - Math, typeset with KaTeX:
- Inline
$…$and$`…`$. - Display
$$…$$and```mathblocks. - Invalid TeX is shown in red rather than breaking the page.
- Dollar amounts like "$5 or $10" are left alone.
- Inline
- Mermaid diagrams in
```mermaidblocks. All diagram types are supported: flowchart, sequence, class, state, entity-relationship, Gantt, pie, git graph, mindmap, timeline and more. A diagram with errors stays visible as source, with the error on hover. - Raw HTML, as READMEs often use it: centered images,
<details>,<kbd>,<sub>/<sup>. - YAML front matter shown as a table, as on GitHub (or hidden with
--front-matter hide). - Numbered headings (1, 1.1, 1.2, …) with
--number-headings, in the page and the contents. - Obsidian notes, on automatically inside a vault (a
.obsidianfolder):[[wiki links]], including[[Note|label]]and[[Note#Heading]], found by name anywhere in the vault. Missing notes are marked.![[image.png]]embeds (with an optional width,![[image.png|300]]).![[Note]]shows the note inline, and![[Note#Heading]]just that section.- A Backlinks tab listing the notes that link to this one (it also works outside a vault, for ordinary Markdown links).
- Callouts (
> [!tip] Title), including folded ones (> [!faq]-). ==highlights==, with%%comments%%hidden.
Viewing
- Opens as a minimal app window (no tabs or address bar), a new window, or a tab, in your default browser or the one you choose (see Opening the page).
- Watch mode (
--watch) updates the page whenever you save:- It scrolls to the first thing you changed and briefly highlights it. Otherwise your scroll position is kept.
- Diagrams and math are drawn before the update is shown, so nothing flickers.
- Works with editors that save by replacing the file.
- Folder mode:
markdown-viewer some/folder(or no argument, for the current folder) shows the folder's README, or a list of its files. Every Markdown file you open from there updates live too. - A sidebar with the document's contents, which follows your place as you scroll, and, when serving, a list of the folder's Markdown files with a filter that also searches their text.
- Double-click a paragraph (or press e) to open the source in your
editor at that line (see Editor). The other way round,
markdown-viewer --goto file.md:42scrolls the preview to a line; the Zed and VS Code integrations use it to follow your cursor. - Reopening a file takes you back to where you were reading.
- Opening a file that's already being viewed brings its window to the front instead of opening another.
- Click an image or diagram to zoom; scroll to zoom further and drag to pan.
- Presentation mode (s): the document as full-screen slides,
split at
---rules (or at headings, if there are none). - Preview standard input (
markdown-viewer -) or the clipboard (--clipboard; with--watchthe page follows the clipboard as it changes). - Larger or smaller text (+ / -), remembered between runs.
- Show what changed since the last git commit (D): changed blocks get a bar in the margin, like an editor's gutter.
- Copy the whole page (c): rich text for Docs, Slack or email, with the Markdown as plain text.
- Check the page's links (l), or every file's with
--check-links(see Checking links). - Large files stay fast: an edit updates only the blocks that changed.
- Word count and reading time in the toolbar.
- Keyboard shortcuts for everything (see In the viewer).
- Your theme and sidebar choices are remembered between runs.
- In watch mode, relative images load, and links to other
.mdfiles open as rendered pages. - Ctrl-C stops watch mode and closes the window it opened.
Exporting
-owrites a single self-contained HTML file (or-o -for stdout), with any diagrams and math included.--pdfwrites a PDF using Chrome, Chromium, Edge, Brave or Vivaldi, with diagrams and math rendered, in light colours, and without page breaks inside code blocks, tables or diagrams.- Printing from the browser uses the same print layout.
Finder (macOS)
- A "Markdown Viewer" app for Markdown files: Open With, double-click (once set as the default), or drop files on its icon. See Finder integration.
- An "Open in Markdown Viewer" Quick Action in Finder's right-click menu.
- Each file opens in its own live-reloading window, and the viewer exits when you close the window.
Offline and safe
- Everything ships inside one binary: stylesheets, fonts, KaTeX and mermaid.js. Pages never contact the network, though images that link to the web still load. KaTeX and Mermaid are only added to pages that use them.
- Scripts inside the Markdown are blocked (see Security).
Install
With Homebrew (macOS and Linux), including shell completions and a man page:
Debian, Ubuntu and Fedora packages (x86_64 and ARM64) are attached to each release:
With Rust's tools (the crate is markdown-viewer-rs; the command is still
markdown-viewer):
Usage
| |
| Option | Description |
|---|---|
-w, --watch |
Serve on 127.0.0.1 and reload the page when the file changes |
-o, --output <PATH> |
Write HTML to PATH (- for stdout) instead of opening it |
--pdf <PATH> |
Write a PDF to PATH (needs a Chromium-based browser) |
-p, --port <N> |
Port for --watch (default: any free port) |
--browser <NAME> |
Open a specific browser, e.g. "Google Chrome" or firefox |
--app |
Open as a minimal app window with no tabs or address bar (default) |
--window |
Open in a normal new browser window |
--tab |
Open in a tab of an existing window |
--no-open |
Don't open a browser |
--theme <auto|light|dark> |
Colour theme (default: the one you last chose, else auto) |
--style <github|wide|book|compact> |
Page style (default: github) |
--css <PATH> |
Extra CSS file, applied after the built-in styles |
--number-headings |
Number headings (1, 1.1, 1.2, …) |
--front-matter <table|hide> |
Show YAML front matter as a table (default) or hide it |
--obsidian, --no-obsidian |
Force Obsidian notes on or off (default: on inside a vault) |
--editor <COMMAND> |
Editor for double-click-to-source (see Editor) |
--clipboard |
Preview the clipboard instead of a file |
--line-numbers |
Number the lines of every code block |
--goto <FILE:LINE> |
Scroll a running viewer to a line, or open one there |
--if-running |
With --goto: do nothing if no viewer is showing the file |
--check-links |
Check the links in a file or folder and report broken ones |
--online |
With --check-links: also check web links (needs curl) |
--exit-when-closed |
With --watch: exit once the page has been closed for 5 seconds |
--install-finder |
macOS: add the Finder integration for your user |
--uninstall-finder |
macOS: remove the Finder integration |
Without --watch, the page is written to your temp directory and opened; no
server keeps running. Giving a folder (or nothing) always serves it with live
reload.
In the viewer
The toolbar in the top-right corner shows the word count and reading time, and has buttons for the contents, the file list (when serving), editing the source, presenting, the theme and help. Hovering a code block shows its copy button.
| Key | Action |
|---|---|
| t | Switch theme: auto, light, dark |
| o | Show or hide the contents |
| f | Find a file (when serving): type to filter, Enter to open |
| / | Search the text of every file (when serving) |
| e | Open the source in your editor here (or double-click a paragraph) |
| s | Present as slides: arrows or space to move, Esc to stop |
| + / - / 0 | Larger / smaller / normal text |
| c | Copy the page |
| b | Backlinks: other files that link here (when serving) |
| l | Check this page's links (when serving) |
| D | Show what changed since the last git commit (when serving) |
| j / k | Scroll down / up |
| d / u | Half a page down / up |
| g / G | Top / bottom |
| n / p | Next / previous heading |
| ? | Show the shortcuts |
| Esc | Close |
The theme, whether the sidebar is open, and where you were in each file are
remembered for next time. --theme overrides the remembered theme for that
run. Pages opened without --watch remember them in the browser instead.
Editor
Double-clicking a paragraph, or pressing e, opens the file in your editor at that line (when serving). The editor is the first of:
--editor, oreditorin the settings file, e.g."zed"or"code -g {file}:{line}".$MARKDOWN_VIEWER_EDITOR.$VISUALor$EDITOR, if it's a known graphical editor.- The first one found of Zed, VS Code, Cursor, Windsurf, VSCodium, Sublime Text, TextMate or IntelliJ IDEA.
- On macOS, the default text editor (without jumping to the line).
Terminal editors such as vim can't be used, as there's no terminal to run them in.
Settings file
Put defaults for any of these options in
~/.config/markdown-viewer/config.toml (or $XDG_CONFIG_HOME/markdown-viewer/config.toml).
Command-line options override it, and a theme you pick in the viewer
overrides its theme.
= "auto" # auto, light or dark
= "book" # github, wide, book or compact
= "~/notes.css" # extra stylesheet
= "window" # app, window or tab
= "Firefox"
= 6419
= "zed" # or "code -g {file}:{line}"
= "table" # table or hide
= true
= true # number every code block
= false # default: on inside an Obsidian vault
Unknown keys are reported as errors, so typos don't go unnoticed. Set
MARKDOWN_VIEWER_CONFIG to use a different file.
Opening the page
By default the page opens as a minimal app window, with no tabs, address bar
or toolbar, so the preview can sit next to your editor. It uses your default
browser, or the one given with --browser.
| Browser | Default (--app) |
--window |
|---|---|---|
| Chrome, Edge, Brave, Chromium, Vivaldi | app window | new window |
| Firefox, Opera, Safari | new window (no app mode) | new window |
| Others | new tab | new tab |
When you stop --watch with Ctrl-C, a window that markdown-viewer opened
closes itself. Some pages stay open instead, showing a "markdown-viewer
stopped" banner:
- A tab, whether from
--tabor a page you opened yourself. - A window you've used to visit another page.
The window size is up to the browser. Chrome ignores size requests when it's already running.
Finder integration (macOS)
This adds two things for your user only, with no admin rights needed:
~/Applications/Markdown Viewer.app, which you can use to open Markdown files:- Open With: right-click a
.mdfile > Open With > Markdown Viewer. - Double-click: to make it the default, use Get Info on a
.mdfile > Open with > Markdown Viewer > Change All…. - Drag and drop: drop files on the app's icon.
- Launched on its own: it asks you to choose a file.
- Open With: right-click a
- A right-click > Quick Actions > Open in Markdown Viewer menu item. It
doesn't change which app opens
.mdfiles. If it's missing, turn it on in Finder's right-click > Quick Actions > Customize…, or in System Settings > Keyboard > Keyboard Shortcuts > Services.
Each file opens with --watch --exit-when-closed, so it updates as you edit
and quits by itself when you close its window. Output goes to
~/Library/Logs/markdown-viewer.log.
The app runs the markdown-viewer you installed it from. For Homebrew that's
the stable bin link, so upgrades keep working. Remove it with
markdown-viewer --uninstall-finder.
Checking links
It reports each broken link as file:line: target (reason) and exits with
status 1 if there are any, so it works in CI. It checks relative files and
images, #anchors (in the same file or another one), and wiki links in an
Obsidian vault. Web links are only checked with --online, which uses
curl.
Editors
markdown-viewer --goto file.md:42 scrolls a running viewer to line 42, or
opens one there. Zed tasks and a VS Code extension that use it are in
editors/: a key to show the cursor's line in Zed, and
following the cursor in VS Code.
Building
You need Rust 1.91 or newer. Install it with rustup, or
run rustup update to upgrade. No other tools or system libraries are needed:
the stylesheets, fonts, icons, KaTeX and mermaid.js are built into the binary.
The binary is target/release/markdown-viewer. To put it on your PATH
(in ~/.cargo/bin):
To run it straight from the source tree without installing:
Development
The browser tests drive the viewer in headless Chrome. They're skipped if no Chrome-family browser is installed, except in CI, where they must run.
The shell completions (completions/) and man page (man/) are generated
from the command-line options, and a test fails if they're out of date.
Regenerate them with:
UPDATE_GENERATED=1
If a change alters rendered output on purpose, the snapshot test fails.
Review and accept the new snapshot with
cargo-insta (cargo install cargo-insta):
Releases are built by GitHub Actions when a v* tag is pushed; see
AGENTS.md.
Security
- Raw HTML: allowed, because READMEs often use it. The page's Content-Security-Policy blocks any script that comes from the Markdown, and KaTeX and Mermaid run in their strict modes.
- Watch server: listens on loopback only and serves only files inside the Markdown file's folder (or the folder you gave it). The file list skips hidden folders and doesn't follow symlinked folders.
- Other websites: requests addressed to any other hostname are rejected, so a website can't read the files being served. Saving preferences also needs a custom header, which other websites can't send to it.
- Editor and reading positions: the page can ask the server to open a file in your editor or to remember a position, but only for Markdown files inside the served folder, and only with a custom header other websites can't send. The editor runs without a shell.
- PDF export: runs the browser headless with a throwaway profile, so it never touches your own browser profile.
License
MIT. Includes:
- github-markdown-css
(MIT, see
assets/LICENSE-github-markdown-css). - KaTeX (MIT, see
assets/LICENSE-katex). - Primer Octicons (MIT, see
assets/LICENSE-octicons). - Mermaid (MIT, see
assets/LICENSE-mermaid).