ThisCalculator

Everyday

Preview Markdown in Terminal with GUI Feel

Updated · Standard formula, shown below

Preview Markdown in Terminal with GUI Feel

To preview Markdown in a terminal with a GUI-like feel, use a terminal-based renderer like glow or mdcat, which display styled, formatted output directly in your terminal window. These tools render headings, bold text, code blocks, and images (in supported terminals) with colors and layout that mimic a graphical preview, without leaving the command line. Below, we cover the best options, how to install and use them, and how to handle common issues.

Why Preview Markdown in the Terminal?

Markdown is a plain-text formatting syntax, but reading raw Markdown with all its #, *, and ` markers can be distracting. A terminal-based preview renders the file as it would appear after conversion to HTML, but stays inside your terminal workflow. This is useful for:

  • Quickly checking a README or documentation file before committing.
  • Editing notes or blog posts without switching windows.
  • Working over SSH on a remote server where a GUI is not available.
  • Keeping your entire workflow in one terminal emulator.

Unlike opening a browser, terminal previews are lightweight, start instantly, and work in any text-based environment.

Top Tools for Terminal Markdown Preview

Several open-source tools provide a GUI-like preview in the terminal. The most popular are:

  • glow – a polished, cross-platform renderer by Charmbracelet, with syntax highlighting, word wrap, and even image support in some terminals.
  • mdcat – uses the terminal’s ANSI styles and supports images via Kitty or iTerm2 protocols, plus syntax highlighting for code blocks.
  • rich-cli – part of the Python rich ecosystem, it can render Markdown with tables, and also offers a live rich.markdown preview.
  • mdless – a pager-like tool that mimics less but renders Markdown with colors and formatting.
  • terminal-markdown-viewer (or tmv) – a simple Node.js-based viewer that works in most terminals.

Each tool has different dependencies and features, so choose based on your terminal emulator and operating system.

How to Install and Use Glow (Recommended)

glow is the most user-friendly option for a GUI-like feel. It renders Markdown with a clean, card-based layout, and it works on Linux, macOS, and Windows (via WSL or native).

Installation:

  • macOS (Homebrew): brew install glow
  • Linux (Debian/Ubuntu): sudo apt install glow (or download the binary from GitHub releases)
  • Windows (Scoop): scoop install glow
  • Go users: go install github.com/charmbracelet/glow@latest

Usage:

  1. To preview a file: glow README.md
  2. To start an interactive file picker: glow (then navigate with arrow keys)
  3. To render from stdin: cat file.md | glow
  4. To copy the rendered output to clipboard: glow -c file.md

Glow automatically detects your terminal’s color support and width. It also supports paging (like less) when the output is longer than the screen – press q to quit.

How to Install and Use mdcat

mdcat is another excellent choice, especially for users of Kitty, iTerm2, or WezTerm, because it can display images inline. It is written in Rust and available via package managers.

Installation:

  • macOS: brew install mdcat
  • Linux: cargo install mdcat (or use your distro’s package, e.g., apt install mdcat on Debian)
  • Windows: cargo install mdcat (requires Rust toolchain)

Usage:

  1. Preview a file: mdcat README.md
  2. To enable image support in Kitty: mdcat --kitty file.md
  3. In iTerm2: mdcat --iterm file.md
  4. To use a specific width: mdcat -w 100 file.md

mdcat uses the terminal’s truecolor support and falls back to 256 colors if needed. It also renders tables and footnotes correctly.

Choosing the Right Tool for Your Terminal

Not all terminals are created equal. The “GUI-like feel� depends on what your terminal supports:

  • Truecolor (24-bit) support: Most modern terminals (iTerm2, GNOME Terminal, Windows Terminal, Alacritty) support truecolor. Glow and mdcat will look great.
  • Image support: Only Kitty, iTerm2, and WezTerm (with kitty protocol) can display images inline. If you use these, mdcat is the best choice.
  • Old terminals (e.g., xterm without truecolor): Glow will still work but with reduced color fidelity.

If you are unsure, run glow on a sample file and see if the colors look right. If not, try mdcat or rich-cli.

Common Problems and Solutions

Even with good tools, you may hit issues:

  • Images not showing: Your terminal must support the image protocol. Use mdcat --kitty or --iterm explicitly. For Glow, images are only shown in terminals that support inline images (like iTerm2) – otherwise they appear as links.
  • Colors look wrong or washed out: Ensure your terminal is set to use truecolor. In some terminals (like GNOME Terminal), you may need to set COLORTERM=truecolor in your shell profile.
  • Output is too wide or wraps badly: Use the -w option (e.g., glow -w 80 or mdcat -w 80) to set a fixed width.
  • Long files are cut off: Both Glow and mdcat page the output by default. If you want to see everything at once, pipe to cat (e.g., glow file.md | cat) – but this loses the formatting in some cases.

Alternative: Live Preview While Editing

If you want a live preview that updates as you type, you can combine a terminal editor with a preview pane:

  • vim/neovim: Use a plugin like markdown-preview.nvim which opens a browser preview, but for terminal-only, use vim-instant-markdown (requires a browser) or glow in a split pane (but it won’t auto-refresh).
  • emacs: Use markdown-mode with markdown-live-preview-mode (opens browser).
  • VS Code in terminal: Not applicable – VS Code is a GUI.

For a true terminal-only live preview, you can run glow in a loop with watch (e.g., watch -n 1 glow file.md), but it will re-render the whole file each second, which is inefficient for large files.

Frequently Asked Questions

Can I preview Markdown in the terminal without installing anything?

Yes, if you have Python, you can use python3 -m rich.markdown file.md (requires the rich package) or use pandoc to convert to HTML and then use a text browser like lynx to view it. However, these are less polished than dedicated tools.

Does glow work on Windows natively?

Yes, glow provides a native Windows binary. It works in Windows Terminal and PowerShell, but for best results, use Windows Terminal with truecolor enabled.

How do I make the preview look exactly like GitHub?

No terminal tool can perfectly replicate GitHub’s CSS, but mdcat and glow come close. For a closer match, you can use grip (which uses the GitHub API) and open it in a browser, but that is not terminal-only.

Can I preview Markdown files from a remote server?

Yes, all these tools work over SSH because they only need the terminal. Just install the tool on the remote machine and run it there.

Is there a way to export the preview to an image or PDF?

Not directly. For PDF, use pandoc to convert to PDF. For an image, you can take a screenshot of the terminal window.

Why does my terminal show raw Markdown instead of formatted output?

This usually means the tool is not installed or the file is not being piped correctly. Check that you are running glow or mdcat directly on the file, not through a pager that strips ANSI codes.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.