Simple shell function for rendering Markdown files to HTML and opening them in your default web browser. Motivated by a dissatisfaction with the lack of lightweight open-source Markdown viewers (not editors) for Linux. Inspired by this Reddit comment.
Run these three commands...
curl --create-dirs -o ~/.pandoc/md2browser.css https://raw.githubusercontent.com/abyrne55/md2browser/refs/heads/main/md2browser.css
curl https://raw.githubusercontent.com/abyrne55/md2browser/refs/heads/main/md2browser.sh >> ~/.bashrc
source ~/.bashrc...or manually follow these instructions:
- Make sure you have
pandoc(for rendering Markdown to HTML) andrumdl(for cleaning up the input Markdown file such that Pandoc renders it properly) installed and in your$PATH - Download the CSS template (md2browser.css to somewhere where Pandoc can find it, e.g.,
~/.pandoc/md2browser.css - Copy the
md()shell function (md2browser.sh) and paste it into your~/.bashrc(or wherever your shell's config lives) - Make customizations if necessary, for example...
md(): changexdg-opentoopenif you're using macOSmd(): remove therumdlline if don't think a linting step is necessarymd2browser.css: change the font, background color, etc.
- Restart your terminal (or run
source ~/.bashrc)
md document.md
# and then your default browser opens a rendered version of document.md :)cats your Markdown file into a linter (rumdl) to fix anything that might trip up the renderer without actually modifying the file- Pipes the linter's output into Pandoc, which uses the provided CSS* to render the linted Markdown input to a self-contained HTML file
- Saves that HTML to a temporary file created using
mktempand named based on the original Markdown file's absolute path - Opens that temporary HTML file in your default web browser
*the provided CSS is just the default CSS that Pandoc uses, plus some quality-of-life tweaks like an automatic dark mode, a sans-serif font, and a wider body column.