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_blocklays out a multi-line value (headings, lists, code, quotes, …) wrapped to a width.render_inlinerenders a single-line value as inline-only markup, clipped to a width; block syntax stays literal.measure_blockreports the line countrender_blockwould produce.linksextracts the hyperlinks of a source (for an “open link” key).clip_spanstruncates a span list to a column budget.
Structs§
- Bullet
Style - Style of list bullets: a colour and the glyphs cycled by nesting depth.
- Callout
Style - Foreground/background of one GFM callout kind (
> [!NOTE]…). - Callout
Theme - Styles for the five GFM callout kinds.
- Checkbox
Style - Style of task-list checkboxes: glyphs and colours per checked state.
- Code
Block Style - Style of fenced/indented code blocks: a full-width band.
- Heading
Style - 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.
- Markdown
View - 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 explicitStyleSheetor, by default, from the skin viaStyleSheet::from_skin. - Quote
Style - Style of blockquotes: text colours plus a left bar glyph.
- Rule
Style - Style of horizontal rules: a colour and the glyph repeated full-width.
- Style
Sheet - 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
maxdisplay columns, appending theellipsis-styled…on overflow. - links
- The hyperlinks in
src, in document order. - measure_
block - The number of lines
render_blockproduces forsrcatwidth. - render_
block - Renders
srcas wrapped, decorated Markdown lines for a box ofwidthcolumns. - render_
inline - Renders
srcas inline-only Markdown spans clipped towidthcolumns. Block syntax (a leading#,>, …) is shown literally. - style_
overlay - A per-character style overlay for
src: oneStyleper 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 ofrender_block/render_inline. Unstyled characters getStyle::default. - viewer
- Opens
sourcein a blocking Markdown viewer overrender_bg.Tabcycles the document’s links (shown in the footer);Enter/oreturns the highlighted link,Esccancels, the global quit chord yieldsQuit.