Expand description
Parse and render Markdown to ANSI-styled terminal output.
§Quick start
One-shot rendering to a string:
use smart_markdown::render_to_string;
let output = render_to_string("# Hello\n\n**bold** and *italic*\n", 80);
println!("{output}");Live in-place terminal rendering with cursor control:
use smart_markdown::Markdown;
let mut md = Markdown::parse("# Loading...\n\n*please wait*");
md.render(); // prints to stdout with ANSI escape codes
// Update content and re-render in-place
// (requires modifying parsed elements — see append_to_cell, set_cell_content)Streaming LLM output with real-time table updates:
use smart_markdown::{StreamRenderer, ThemeMode, is_light_terminal};
let width = 80;
let theme = if is_light_terminal() { ThemeMode::Light } else { ThemeMode::Dark };
let mut sr = StreamRenderer::new(width, theme)
.with_ascii_table_borders(true);
// Feed chunks as they arrive from the LLM
for line in sr.push("# Hello\n\n") {
println!("{line}");
}
for line in sr.push("| Name | Value |\n") {
println!("{line}");
}
for line in sr.push("|------|-------|\n") {
println!("{line}");
}
// Table will render and re-render as new rows are added
for line in sr.push("| CPU | 45% |\n") {
println!("{line}");
}
for line in sr.push("| Mem | 67% |\n") {
println!("{line}");
}
for line in sr.flush_remaining() {
println!("{line}");
}Re-exports§
pub use highlight::ThemeMode;
Modules§
- highlight
- Syntax highlighting for fenced code blocks.
Structs§
- Markdown
- A parsed Markdown document with support for live in-place terminal rendering.
- Stream
Renderer - Incrementally renders markdown text chunks as they arrive.
Functions§
- is_
light_ terminal - Returns
trueif the terminal background is light-colored. - render_
to_ string - Render a markdown string to a single
Stringwith ANSI styling.