8

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?

4
  • 1
    Formatted how? There isn't that much you can do to format text on the command line, e.g. different font sizes aren't really possible. Commented Oct 27, 2016 at 13:44
  • 1
    define "easy". what may be such for one may not be for another... have you done a google search? there are lots of options - one is installing a viewer like this one: github.com/axiros/terminal_markdown_viewer Commented Oct 27, 2016 at 13:44
  • I'm looking for some package that will take MD file format, convert it to something that will display close to that format in command line (as much as command line can accommodate the formatting). Anything like that exists? Commented Oct 27, 2016 at 13:49
  • 1
    yes something like that exists, but you have to search to see what is available. Commented Oct 27, 2016 at 13:53

4 Answers 4

10

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

0

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.

1 Comment

Its 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.
-1

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.

1 Comment

In the vein of non-python3 modules, github.com/charmbracelet/glow might be a superior choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.