A fast terminal markdown renderer and toolchain built in Rust. Renders markdown with syntax highlighting, tables, and images — directly in your terminal. In browser preview mode (mdx serve), also supports math (KaTeX) and mermaid diagrams. Includes a formatter, linter, diff viewer, full-text search, format converter, web page fetcher, and static site generator.
macOS / Linux:
curl -fsSL https://raw.githubusercontent.com/Harsh-2002/mdx/main/install.sh | shWindows (PowerShell):
irm https://raw.githubusercontent.com/Harsh-2002/mdx/main/install.ps1 | iexInstalls the binary and sets up shell completions automatically.
From source (all platforms):
cargo install --git https://github.com/Harsh-2002/mdx --features servemdx file.md # render in terminal
mdx file.md --pager # render and pipe through less
cat README.md | mdx # read from stdin
mdx https://example.com/doc.md # render from URL
mdx serve file.md # browser preview with live reload
mdx serve ./notes/ # serve a directory as a note-taking app
mdx serve a.md b.md # serve multiple files with index page
mdx search "query" ./docs/ # full-text search across markdown files
mdx search --tag rust "ownership" # filter by front matter tag
mdx fetch https://example.com # fetch web page as markdown
mdx fetch -o article.md URL # save fetched markdown to file
mdx export --to html file.md # export to standalone HTML
mdx export --to pdf file.md # export to PDF
mdx export --to epub file.md # export to EPUB e-book
mdx export --to json file.md # export AST as JSON
mdx export --to txt file.md # strip formatting to plain text
mdx stats file.md # show word count, headings, reading time
mdx toc file.md # print table of contents
mdx fmt file.md # format/prettify markdown
mdx fmt --check file.md # check formatting (for CI)
mdx lint file.md # check for broken links, issues
mdx diff old.md new.md # colored side-by-side diff
mdx present file.md # slide presentation in terminal
mdx watch file.md # re-render on file changes
mdx publish ./blog --out ./dist # generate a static site
mdx update # self-update to latest version
mdx completions install # install shell completions| Flag | Description |
|---|---|
-w, --width <N> |
Output width in columns |
-p, --pager |
Pipe through less (or more on Windows) |
--color auto|always|never |
Color output mode |
--plain |
Plain text, no colors or box-drawing |
--theme dark|light |
Color theme |
--syntax-theme <NAME> |
Syntax highlighting theme |
--list-syntax-themes |
List available syntax themes |
--css <FILE> |
Custom CSS for HTML/serve output |
--generate-man |
Generate man page |
Turns markdown into a live browser preview with hot reload.
mdx serve file.md # single file with live reload
mdx serve ./notes/ # directory as card grid, click to view
mdx serve a.md b.md c.md # multiple files with sidebar navigation
mdx serve file.md -p 8080 # specify port
mdx serve file.md --css custom.css # inject custom CSSAll modes include:
- Built-in markdown editor (toggle with pencil icon or
e) - Search & replace in editor (
Ctrl+F/Ctrl+H) - Drag & drop image upload (or paste from clipboard)
- Print / PDF export button (uses browser's native print)
- Dark/light theme toggle
- Table of contents sidebar
- Markdown for Agents — AI agents sending
Accept: text/markdownget raw markdown withX-Markdown-TokensandVary: Acceptheaders instead of HTML
| Key | Action |
|---|---|
e |
Toggle editor |
t |
Toggle dark/light theme |
[ |
Toggle sidebar |
] |
Switch sidebar tab |
Ctrl+F |
Search in editor |
Ctrl+H |
Search & replace in editor |
BM25-ranked search across markdown files. Headings are weighted higher than body text, body text higher than code. Files are parsed in parallel.
mdx search "rust async" . # search current directory
mdx search "BM25" docs/ # search recursively
mdx search --tag rust "ownership" # filter by front matter tag
mdx search -n 5 "error" . # top 5 results
mdx search -l "query" . # list matching file paths onlyResults show the file path, matching heading context, and a highlighted snippet. Automatically skips .git, node_modules, target, and other non-content directories.
Fetches a web page, extracts the main content using readability, and renders it as clean markdown. When piped, outputs raw markdown (great for LLM pipelines).
Supports the Markdown for Agents (MFA) protocol: sends Accept: text/markdown so MFA-enabled sites return pre-converted markdown directly.
mdx fetch https://example.com # extract & render in terminal
mdx fetch --raw https://example.com # full HTML to markdown (skip readability)
mdx fetch --metadata https://example.com # include YAML front matter (title, date, etc.)
mdx fetch --tokens https://example.com # show estimated token count
mdx fetch -o article.md https://example.com # save to file
mdx fetch https://example.com | llm # pipe to LLMExport markdown to other formats. PDF and EPUB write to a file (defaults to input filename with new extension). HTML, JSON, and TXT print to stdout.
mdx export --to html README.md # standalone HTML page
mdx export --to pdf README.md # PDF document (native, no browser needed)
mdx export --to epub README.md # EPUB e-book (Apple Books, Kobo, Calibre)
mdx export --to json README.md # AST as JSON
mdx export --to txt README.md # plain text (strip formatting)
mdx export --to pdf -o out.pdf file.md # custom output pathEPUB export embeds local images, maps front matter to EPUB metadata (title, tags), and preserves syntax-highlighted code blocks.
$ mdx stats README.md
Words: 1,247
Lines: 89
Chars: 7,832
Headings: 12
Links: 8
Images: 0
Code blocks: 3
Reading time: ~5 min
Extracts headings and prints a linked table of contents.
mdx toc README.md # default depth (h1-h3)
mdx toc --depth 2 README.md # only h1-h2
mdx toc --depth 6 README.md # all heading levelsNormalizes markdown formatting. Use --check in CI to ensure consistent style.
mdx fmt README.md # print formatted to stdout
mdx fmt --in-place README.md # overwrite the file
mdx fmt --check README.md # exit 1 if not formattedChecks for broken relative links, duplicate headings, missing image alt text, and trailing whitespace.
$ mdx lint README.md
README.md:12 broken link: ./missing.md
README.md:34 image missing alt text
README.md:45 duplicate heading: "Setup"
3 issues found
Colored side-by-side or unified diff of two markdown files.
mdx diff old.md new.md # side-by-side
mdx diff -u old.md new.md # unified
mdx diff - new.md # read first file from stdinGenerates a static site from a directory of markdown files.
mdx publish ./blog --out ./distSupports YAML front matter:
---
title: My Post Title
date: 2024-01-15
tags: rust, cli
draft: true
---draft: truefiles are skipped- Missing
datefalls back to file modification time - Missing
titlefalls back to first heading or filename - Generates clean URLs:
my-post.mdbecomesmy-post/index.html - Shared CSS, blog index with cards, dark/light theme
Presents markdown as slides in the terminal. Splits content on --- separators.
mdx present slides.mdRe-renders markdown in the terminal when the file changes.
mdx watch file.mdUpdates mdx to the latest release from GitHub.
mdx updatemdx completions install # auto-detect shell and install
mdx completions bash # print bash completions to stdout
mdx completions zsh # print zsh completions to stdout
mdx completions fish # print fish completions to stdout
mdx completions powershell # print PowerShell completions to stdout- Syntax highlighting — language-aware code blocks via syntect
- Tables — full GFM table rendering with alignment and cell wrapping
- Mermaid diagrams — rendered as interactive SVG in browser preview via mermaid.js
- Math — inline
$...$and display$$...$$via KaTeX in browser preview - Images — inline image rendering in supported terminals (iTerm2, kitty)
- URL fetching — render markdown directly from URLs
- Web page extraction —
mdx fetchextracts article content as clean markdown, with MFA content negotiation - Markdown for Agents —
mdx serveresponds with raw markdown when agents sendAccept: text/markdown - Live reload —
mdx serveopens a browser preview that updates on file changes - Built-in editor — toggle a markdown editor in the browser, saves back to disk
- Search & replace — find and replace text in the editor with regex support
- Image upload — drag & drop or paste images into the editor
- Print / PDF — browser-native print with clean print-optimized CSS
- Directory mode —
mdx serve ./dir/shows a file index with card grid - Multi-file mode —
mdx serve a.md b.mdwith sidebar file navigation - Dark/light theme — toggle with button or
tkey, persisted in localStorage - Full-text search — BM25-ranked search across markdown files with
mdx search - Slide presentation —
mdx presentsplits on---for terminal slides - ToC generation —
mdx tocextracts headings with depth control - Document stats — word count, reading time, heading/link/image counts
- Formatter — normalize markdown style with
mdx fmt - Linter — check for broken links, duplicates, missing alt text
- Diff viewer — colored side-by-side or unified diff
- Format export — export to HTML, PDF, EPUB, JSON AST, or plain text
- Static site generator —
mdx publishbuilds a blog from markdown files - Alerts — GitHub-style note/tip/warning/caution blocks
- Footnotes, task lists, strikethrough, autolinks — full GFM support
mdx parses markdown into an AST using comrak (a CommonMark + GFM parser), then walks the tree to produce styled terminal output using ANSI escape codes. Text wrapping respects terminal width. For browser preview, it generates HTML and serves it via a local HTTP server with SSE-based live reload.
markdown file
|
v
comrak ──> AST
|
├──> terminal renderer ──> ANSI output
|
├──> HTML renderer ──> axum server ──> browser (live reload via SSE)
|
└──> CLI tools (stats, toc, fmt, lint, diff, search, export, fetch, publish)
Built on these libraries:
| Library | Purpose |
|---|---|
| comrak | Markdown parsing (CommonMark + GFM) |
| syntect | Syntax highlighting for code blocks |
| clap | CLI argument parsing and completions |
| axum | HTTP server (serve mode) |
| tokio | Async runtime |
| notify | File system watcher (live reload) |
| ratatui | TUI framework (watch/present modes) |
| crossterm | Terminal manipulation |
| similar | Text diffing |
| rayon | Parallel file parsing (search) |
| walkdir | Recursive directory traversal |
| textwrap | Text wrapping |
| image | Image decoding (PNG, JPEG, GIF, WebP) |
| genpdfi | PDF generation |
| markdown2pdf | Markdown to PDF conversion |
| epub-builder | EPUB e-book generation |
| ureq | HTTP client (URL fetching) |
| dom_smoothie | Web article extraction (Readability) |
| htmd | HTML to markdown conversion |
MIT