Emily
Emily

Reputation: 2331

How To Display Markdown Text In Command Line?

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?

Upvotes: 5

Views: 5408

Answers (4)

Richard
Richard

Reputation: 149

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.

Upvotes: 0

Karsten
Karsten

Reputation: 2433

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)

Upvotes: 0

user22155941
user22155941

Reputation:

You can use rich module as well.

from rich.console import Console
from rich.markdown import Markdown
console = Console()
with open('path/to/your/markdown.md') as f:
    md = Markdown(f.read())
    console.print(md)

Upvotes: 4

David Jones
David Jones

Reputation: 5184

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.

Upvotes: -1

Related Questions