mdx

A fast, single-binary markdown toolchain built in Rust. Render in the terminal with syntax highlighting, preview in the browser with live reload, search, fetch web pages, format, lint, diff, export to HTML/PDF/EPUB, and publish — all from one command.

By Anurag Vishwakarma ·

Install

bashcurl -fsSL https://raw.githubusercontent.com/Harsh-2002/mdx/main/install.sh | sh
powershellirm https://raw.githubusercontent.com/Harsh-2002/mdx/main/install.ps1 | iex
bashcargo install --git https://github.com/Harsh-2002/mdx --features serve

Installs the binary and sets up shell completions automatically. Works on macOS, Linux (glibc and musl), and Windows. Supports x86_64 and ARM64.

Pre-built binaries

Each release includes pre-built binaries for every supported platform. Download the one that matches your system:

BinaryPlatformArchitecture
mdx-x86_64-apple-darwin.tar.gzmacOSx86_64 (Intel)
mdx-aarch64-apple-darwin.tar.gzmacOSARM64 (Apple Silicon)
mdx-x86_64-unknown-linux-gnu.tar.gzLinux (glibc)x86_64
mdx-x86_64-unknown-linux-musl.tar.gzLinux (musl)x86_64
mdx-aarch64-unknown-linux-gnu.tar.gzLinux (glibc)ARM64
mdx-aarch64-unknown-linux-musl.tar.gzLinux (musl)ARM64
mdx-armv7-unknown-linux-gnueabihf.tar.gzLinux (glibc)ARMv7 (32-bit)
mdx-x86_64-pc-windows-msvc.tar.gzWindowsx86_64
mdx-aarch64-pc-windows-msvc.tar.gzWindowsARM64

Extract and move the binary to a directory in your PATH:

bashtar xzf mdx-<target>.tar.gz
sudo mv mdx /usr/local/bin/

Quick Start

bashmdx README.md                          # render in terminal
mdx README.md --pager                  # pipe through less
mdx serve file.md                      # live preview in browser
mdx serve ./notes/                     # serve a directory of notes
mdx search "query" ./docs/             # full-text search across files
mdx fetch https://example.com          # fetch web page as markdown
mdx export --to epub file.md           # export to EPUB e-book
mdx update                             # self-update to latest version
cat README.md | mdx                    # read from stdin
mdx https://example.com/doc.md         # render from URL

Features

CLI Tools

mdx fetch — Web page to markdown

Fetches a web page, extracts the main article content using Mozilla Readability, and outputs clean markdown. Supports the Markdown for Agents protocol — MFA-enabled sites return pre-converted markdown directly. Great for LLM pipelines.

bashmdx fetch https://example.com              # extract article as markdown
mdx fetch --raw https://example.com        # full HTML to markdown (sanitizes scripts)
mdx fetch --metadata https://example.com   # include YAML front matter
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 LLM

mdx toc — Table of contents

Extracts headings from a markdown file and prints a table of contents with configurable depth.

bashmdx toc README.md              # print table of contents
mdx toc --depth 2 README.md    # limit to h1 and h2

mdx stats — Document statistics

Word count, reading time, headings, links, images, and code blocks at a glance.

$ mdx stats README.md
     Words: 1,247
     Lines: 89
  Headings: 12
     Links: 8
Code blocks: 3
Reading time: ~5 min

mdx fmt — Markdown formatter

Normalizes markdown formatting. Use --check in CI to enforce consistent style.

bashmdx 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 formatted (CI)

mdx lint — Markdown linter

Checks for broken 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

mdx diff — Markdown diff

Colored side-by-side or unified diff of two markdown files.

bashmdx diff old.md new.md           # side-by-side
mdx diff -u old.md new.md        # unified
mdx diff - new.md                # read first file from stdin

mdx search — Full-text search

BM25-ranked search across markdown files. Headings are weighted higher than body text, body higher than code. Files are parsed in parallel. Automatically skips .git, node_modules, target, and other non-content directories.

bashmdx search "rust async" .            # search current directory
mdx search "query" 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 only

mdx export — Format conversion

Export markdown to standalone HTML, PDF, EPUB, JSON AST, or plain text. EPUB embeds local images and maps front matter to metadata.

bashmdx export --to html README.md   # standalone HTML page
mdx export --to pdf README.md    # PDF (native, no browser needed)
mdx export --to epub README.md   # EPUB e-book
mdx export --to json README.md   # AST as JSON (for tooling)
mdx export --to txt README.md    # plain text (strip formatting)

mdx publish — Static site generator

Generate a static site from a directory of markdown files. Supports YAML front matter for titles, dates, tags, and draft status.

bashmdx publish ./blog --out ./dist

mdx update — Self-update

Updates mdx to the latest release from GitHub. Downloads the correct binary for your platform automatically.

bashmdx update

mdx completions — Shell completions

Generate or install tab completions for your shell. Supports bash, zsh, fish, and PowerShell.

bashmdx completions install              # auto-detect shell and install
mdx completions bash                 # print bash completions
mdx completions zsh                  # print zsh completions
mdx completions fish                 # print fish completions
mdx completions powershell           # print PowerShell completions

mdx present — Slide presentation

Present markdown as slides in the terminal. Splits content on --- separators.

bashmdx present slides.md

mdx watch — Watch mode

Re-renders markdown in the terminal whenever the file changes.

bashmdx watch file.md

Serve Mode

mdx serve turns your markdown into a live browser preview with three modes:

Single filemdx serve file.md opens a live preview. Edit in your editor, the browser updates instantly on save.

Directorymdx serve ./notes/ shows all .md files as a card grid. Click any card to view it, or click "+" to create a new note.

Multiple filesmdx serve a.md b.md c.md serves the listed files with sidebar navigation and search.

All modes include a built-in editor, image upload (drag and drop or paste), print/PDF export, dark/light theme, and a table of contents sidebar. AI agents sending Accept: text/markdown get raw markdown with X-Markdown-Tokens and Vary: Accept headers instead of HTML (Markdown for Agents protocol).

KeyAction
eToggle editor
tToggle dark/light theme
[Toggle sidebar
]Switch sidebar tab
Ctrl+FSearch in editor
Ctrl+HSearch and replace

How It Works

mdx parses markdown into an AST using comrak (CommonMark + GFM), then walks the tree to produce either styled terminal output with ANSI escape codes, or HTML served via a local 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)

Credits

mdx is built on top of these open-source libraries:

LibraryPurpose
comrakMarkdown parsing (CommonMark + GFM)
syntectSyntax highlighting for code blocks
clapCLI argument parsing and completions
axumHTTP server (serve mode)
tokioAsync runtime
notifyFile system watcher (live reload)
ratatuiTUI framework (watch and present modes)
crosstermTerminal manipulation
similarText diffing
rayonParallel file parsing (search)
walkdirRecursive directory traversal
textwrapText wrapping
imageImage decoding (PNG, JPEG, GIF, WebP)
genpdfiPDF generation
markdown2pdfMarkdown to PDF conversion
epub-builderEPUB e-book generation
ureqHTTP client (URL fetching)
dom_smoothieWeb article extraction (Readability)
htmdHTML to markdown conversion
Back to top