Expand description
Convert Markdown into Ratatui Text.
from_str renders with the default styles and options. from_str_with_options accepts an
Options value for custom StyleSheet styles and symbols, image fallback mode, and, when
the highlight-code feature is enabled, syntax-highlighting theme.
The returned text may borrow from the Markdown input. It contains terminal text and styles only; image syntax produces a configurable text fallback and does not read or render image resources.
§Markdown output
Tables use Unicode box-drawing borders, terminal display widths, and the alignment declared by
the Markdown delimiter row. Raw HTML stays visible as literal text. Math retains its delimiters,
and images render as [img] followed by their description or destination.
§Syntax highlighting
The default highlight-code feature highlights fenced code blocks whose language is recognized.
It uses Base16OceanDark unless Options selects another CodeTheme. Themes can come from
the built-in set, TextMate source bundled with the application, or a TextMate file read before
rendering. Unrecognized code fences use StyleSheet::code instead.
§Features
highlight-code(enabled by default) — Enable syntax highlighting using syntect and ansi-to-tui
§Example
use ratatui::text::Text;
use tui_markdown::from_str;
let markdown = r#"
This is a simple markdown renderer for Ratatui.
- List item 1
- List item 2
```rust
fn main() {
println!("Hello, world!");
}
```
"#;
let text = from_str(markdown);
frame.render_widget(text, frame.area());Structs§
- Code
Theme - An owned syntax-highlighting theme for fenced code blocks.
- Code
Theme Load Error - An error returned when a syntax-highlighting theme cannot be parsed or loaded.
- Default
Style Sheet - The default style set
- Options
- Rendering options for
crate::from_str_with_options.
Enums§
- Alert
Kind - The kind of a GitHub Flavored Markdown alert.
- Builtin
Code Theme - A syntax-highlighting theme bundled with tui-markdown.
- Image
Fallback - Text used to represent Markdown images in rendered terminal output.
Traits§
- Style
Sheet - Visual styles and symbols consumed by the renderer.