Skip to main content

Module markdown

Module markdown 

Source
Expand description

CommonMark for the terminal, built on pulldown_cmark.

The level texts are written for Rich: paragraphs are wrapped by hand in the source and are expected to reflow, headings are left-aligned, and code blocks hold box-drawing trees that must survive untouched. The renderer therefore works in two steps. The parser events are first collected into a small block tree; the tree is then laid out for a given width, which makes hanging indents trivial: a list item or block quote simply lays out its children at a smaller width and prefixes the resulting lines.

MarkdownRendering
paragraphreflowed; soft breaks become spaces, hard breaks stay
#, ##the heading in bold underline followed by ──── to the full width
### and deeperthe heading text in bold (h4 dim, h5/h6 italic)
*em*, **strong**, `code`italic, bold, bold cyan; a code span is not split across lines while it fits on one
- item• marker in bold yellow, continuation lines indented under the text
1. itemright-aligned numbers, same hanging indent; nested lists indent further
fenced or indented codeverbatim, never wrapped, indented by two spaces
> quoteevery line prefixed with ▌ , text in magenta

Blocks are separated by exactly one blank line, items of a list by none. Raw HTML is shown as text. Control characters in the input are replaced, so a document can never write escape sequences of its own, and ⚠️ is shown as the bare ⚠ (see normalize_emoji). Tables and the other CommonMark extensions are not enabled.

Functions§

render_markdown
Renders CommonMark to terminal lines, term.width columns wide.
split_pages
Splits intro text into pages at lines that consist of exactly ---.