Skip to main content

Crate discount

Crate discount 

Source
Expand description

§Discount - A terminal-oriented Markdown parser

This is my Markdown parser.
There are many like it, but this one is mine.

In fact, there are not many like it. Most Markdown parsers are focused on outputting Markdown text as HTML. Discount is focused on outputting text that is suitable for display in a terminal.

“But Markdown is plaintext that is already suitable for display on a terminal!” you wail. That’s true, but sometimes it’s nice to see colors and underlines and other styling, even when you’re locked into the command line. That’s where Discount comes in: the parser not only styles text according to some basic rules, but it wraps text to the width of the terminal. And it styles text based on the capabilities of the most basic of terminals: it doesn’t use any styling beyond underlining and bold (“bright”) text, so it’s still as easy on the eyes as plaintext.

Discount consists of two distinct parsers:

  • terminal formats a Markdown document for display in the terminal, with basic styling like underling and bold text, as well as indentation for lists and code blocks. It wraps text to the width of the terminal, including indented text. It makes Markdown look even nicer to read in terminals!

  • plain strips all formatting instructions from Markdown source code, emitting only the content of the Markdown document. It completely removes link URLs, quoted text, headers, image links, and other text accoutrement.

    The plain parser is primarily useful for returning stripped text suitable for passing to an LLM. Thus it is not a completely accurate summary, as some text is completely removed, but it should be “good enough” for an LLM.

Pick the poison suitable to your project.

§See also

Modules§

plain
A bare Markdown parser.
terminal
Markdown parsing engine for terminals.
text
Helpful utilities for working with text.

Traits§

Visitable
A data structure that can be visited.
Visitor
“Visit” a node and emit code.

Functions§

plain
Converts Markdown markup into a string that has been stripped of nearly all markup, including quoted text, headers, image links, and link URLs.
terminal
Converts Markdown markup into a formatted string suitable for output on a terminal.