render
Block IR into styled terminal output.fn render
pub fn render(blocks: &[Block], width: usize) -> StringRender 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
fn render_block(block: &Block, width: usize) -> StringRender 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
fn render_block_quote(blocks: &[Block], kind: Option<BlockQuoteKind>, width: usize) -> StringRender 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
fn render_code_block(content: &str) -> StringRender 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
fn render_heading(inlines: &[Inline], level: HeadingLevel) -> StringRender 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
fn render_inline(inline: &Inline) -> StringRender a single inline element.
| Parameter | Type | Description |
|---|---|---|
inline |
&Inline | the inline element to render |
| returns | String | The styled inline text. |
fn render_inlines
fn render_inlines(inlines: &[Inline]) -> StringRender 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_link
fn render_link(text: &[Inline], url: &str, link_style: Style) -> StringRender a link as an OSC 8 hyperlink escape sequence wrapping the styled text.
| Parameter | Type | Description |
|---|---|---|
text |
&[Inline] | the visible link text |
url |
&str | the link target written into the OSC 8 escape |
link_style |
Style | the style for the visible text |
| returns | String | The styled text, wrapped in an OSC 8 escape only when color output is enabled. |
fn render_list
fn render_list(items: &[Vec<Block>], ordered: bool, width: usize) -> StringRender 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
fn render_paragraph(inlines: &[Inline], width: usize) -> StringRender 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
fn render_rule(width: usize) -> StringRender 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
fn word_wrap(text: &str, width: usize) -> StringWord-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. |