Skip to main content

Module markdown

Module markdown 

Source
Expand description

A small, self-contained Markdown renderer for ratatui.

Turns CommonMark (plus strikethrough, task lists, GFM tables/callouts and a ==highlight== extension) into styled Lines and Spans. The engine depends only on ratatui, pulldown-cmark and unicode-width and carries no colour policy: the host supplies a StyleSheet. StyleSheet::default and StyleSheet::from_skin provide a ready look; MarkdownView and viewer add scrolling and link navigation on top.

Rendering is display-only: it hides Markdown markers and reflows text, so it must not be used where a text cursor indexes the raw string (editing surfaces keep showing the raw source, for which style_overlay exists).

  • render_block lays out a multi-line value (headings, lists, code, quotes, …) wrapped to a width.
  • render_inline renders a single-line value as inline-only markup, clipped to a width; block syntax stays literal.
  • measure_block reports the line count render_block would produce.
  • links extracts the hyperlinks of a source (for an “open link” key).
  • clip_spans truncates a span list to a column budget.

Structs§

BulletStyle
Style of list bullets: a colour and the glyphs cycled by nesting depth.
CalloutStyle
Foreground/background of one GFM callout kind (> [!NOTE] …).
CalloutTheme
Styles for the five GFM callout kinds.
CheckboxStyle
Style of task-list checkboxes: glyphs and colours per checked state.
CodeBlockStyle
Style of fenced/indented code blocks: a full-width band.
HeadingStyle
Style of one heading level: foreground, bold, and an optional full-width background band (None = no band).
Link
A hyperlink found in a source, with its visible text and destination URL.
MarkdownView
A scrollable Markdown view: renders a source wrapped to the render width, keeps a scroll offset across frames and cycles the document’s hyperlinks with Tab/BackTab. The styling comes from an explicit StyleSheet or, by default, from the skin via StyleSheet::from_skin.
QuoteStyle
Style of blockquotes: text colours plus a left bar glyph.
RuleStyle
Style of horizontal rules: a colour and the glyph repeated full-width.
StyleSheet
The complete set of styles a host supplies to render Markdown. Every element is described here, so the renderer itself stays free of any colour policy.

Functions§

clip_spans
Clips a span list to max display columns, appending the ellipsis-styled on overflow.
links
The hyperlinks in src, in document order.
measure_block
The number of lines render_block produces for src at width.
render_block
Renders src as wrapped, decorated Markdown lines for a box of width columns.
render_inline
Renders src as inline-only Markdown spans clipped to width columns. Block syntax (a leading # , > , …) is shown literally.
style_overlay
A per-character style overlay for src: one Style per character, to be patched onto the caller’s base style. Markdown markers are kept (so the styles align 1:1 with the raw characters and survive a text cursor), making this the edit-mode counterpart of render_block/render_inline. Unstyled characters get Style::default.
viewer
Opens source in a blocking Markdown viewer over render_bg. Tab cycles the document’s links (shown in the footer); Enter/o returns the highlighted link, Esc cancels, the global quit chord yields Quit.