I have a command line tool that needs to display short help files on hot key inputs.
Currently help files are in markdown format.
Is there an easy way to display that markdown text in command line formatted?
I have a command line tool that needs to display short help files on hot key inputs.
Currently help files are in markdown format.
Is there an easy way to display that markdown text in command line formatted?
You can use the Python package Rich:
pip install rich
Then:
from rich.console import Console
from rich.markdown import Markdown
console = Console()
with open('path/to/your/markdown.md') as f:
renderable_markup = Markdown(f.read())
console.print(renderable_markup)
The typical recommendation I've found is mdless, which is written in Ruby and needs to be installed using gem install mdless (more information at Github).
A simpler (single binary) implementation however is mdcat, which is written in Rust and can be found at Github. It also includes precompiled binaries ready for download.
Why use such tools instead of just cat when "Markdown is already human readable"? Colors and simple emphasis! (just imagine this answer would be rendered without highlights of the cli-commands, it's a lot harder to find the relevant information quickly)
Rich-cli is nice option for Python users. See: rich-cli GitHub URL
Rich-cli is built on top of the powerful Python package rich which provides rich text and beautiful formatting in the terminal. It supports popular formats like .py, .csv, .md etc.
ReadMe is a little confusing: github.com/Textualize/rich-cli/blob/… and github.com/Textualize/rich-cli/blob/… appear to demonstrate that unless an .MD file is piped, it accepts BBCode-like syntax instead.The nd tool can do it. It is written in node.js and primarily aimed at node.js package documentation. Which may or may not be suitable for your needs.
python3 modules, github.com/charmbracelet/glow might be a superior choice.