render

Render pass: convert the Block IR into styled terminal output.

fn render

source

pub fn render(blocks: &[Block], width: usize) -> String

Render a list of blocks to a styled string fitted to width columns.

Parameter Type Description
blocks &[Block] the blocks to render, separated by one newline each
width usize the column budget for wrapping; 0 turns wrapping off
returns String The styled text, empty when there are no blocks.

fn render_block

source

fn render_block(block: &Block, width: usize) -> String

Render a single block.

Parameter Type Description
block &Block the block to render
width usize the column budget for wrapping; 0 turns wrapping off
returns String The styled block, usually ending in a newline.

fn render_block_quote

source

fn render_block_quote(blocks: &[Block], kind: Option<BlockQuoteKind>, width: usize) -> String

Render a block quote with | borders on every line, dispatching colour by alert kind.

Parameter Type Description
blocks &[Block] the quoted blocks, rendered two columns narrower to leave room for the border
kind Option<BlockQuoteKind> the GitHub alert kind, which picks the border color; None for a plain quote
width usize the column budget for wrapping; 0 turns wrapping off
returns String The quote, one bordered line per rendered line.

fn render_code_block

source

fn render_code_block(content: &str) -> String

Render a fenced code block with a left border. Lines are emitted verbatim — no wrapping.

Parameter Type Description
content &str the code, without its fences
returns String The bordered code, each line ending in a newline.

fn render_heading

source

fn render_heading(inlines: &[Inline], level: HeadingLevel) -> String

Render a heading: # × level prefix, styled text, and a trailing blank line.

Parameter Type Description
inlines &[Inline] the heading text
level HeadingLevel the heading level, which sets the number of # characters
returns String The styled heading followed by a blank line.

fn render_inline

source

fn render_inline(inline: &Inline) -> String

Render a single inline element.

Parameter Type Description
inline &Inline the inline element to render
returns String The styled inline text.

fn render_inlines

source

fn render_inlines(inlines: &[Inline]) -> String

Render a sequence of inlines into a single styled string.

Parameter Type Description
inlines &[Inline] the inline elements, rendered in order
returns String Their styled text, joined with nothing between them.

fn render_list

source

fn render_list(items: &[Vec<Block>], ordered: bool, width: usize) -> String

Render a list, recursively rendering each item’s blocks with a marker prefix.

Parameter Type Description
items &[Vec<Block>] each item’s blocks
ordered bool whether markers are 1., 2. and so on, rather than •
width usize the column budget; each item gets it less its marker’s width
returns String The list, with item continuation lines indented under the marker.

fn render_paragraph

source

fn render_paragraph(inlines: &[Inline], width: usize) -> String

Render a paragraph: word-wrap inlines to width and emit a trailing newline.

Parameter Type Description
inlines &[Inline] the paragraph text
width usize the column budget for wrapping; 0 turns wrapping off
returns String The wrapped paragraph ending in a newline.

fn render_rule

source

fn render_rule(width: usize) -> String

Render a horizontal rule as a styled ─ line spanning width.

Parameter Type Description
width usize the rule length in columns
returns String The styled rule ending in a newline.

fn word_wrap

source

fn word_wrap(text: &str, width: usize) -> String

Word-wrap a string to fit within width columns. Width 0 disables wrapping.

This is intentionally width-aware (uses display width, not byte length) but does not understand ANSI escape sequences embedded in the input — styled inlines may push lines slightly past width. Wrapping is best-effort for human readability.

Parameter Type Description
text &str the text to wrap; existing newlines are kept
width usize the column budget for wrapping; 0 turns wrapping off
returns String The wrapped text. Words longer than width stay whole on their own line.