Simple Markdown rendering utilities for Rust.
mdkit is inspired by unjs/mdbox. It keeps
the same small idea: provide useful Markdown string helpers without requiring
an AST or a large framework. The output is intentionally straightforward, and
the helpers do not escape input text.
Add mdkit to your Cargo.toml:
[dependencies]
mdkit = "0.1"use mdkit::{bold, heading, list, ListOptions};
assert_eq!(heading("Hello", 2), "\n## Hello\n");
assert_eq!(bold("Hello"), "**Hello**");
assert_eq!(
list(&["One", "Two"], ListOptions::default()),
"- One\n- Two"
);All helpers return String values.
heading(text, level)renders a heading. Levels are clamped to 1 through 6.bold(text)renders bold text.italic(text)renders italic text.bold_and_italic(text)renders bold and italic text.strikethrough(text)renders strikethrough text.blockquote(text)prefixes each line with>.hr()renders---.hr_with_length(length)renders a horizontal rule with a custom length.
link(url, text, LinkOptions)renders a Markdown link. Setexternal: trueto render an HTML link withtarget="_blank".image(url, text, ImageOptions)renders a Markdown image.code_block(code, language, CodeBlockOptions)renders a fenced code block.
LinkOptions, ImageOptions, and CodeBlockOptions implement Default, so
the common case does not need any options:
use mdkit::{code_block, link, CodeBlockOptions, LinkOptions};
let url = link("https://example.com", Some("Example"), LinkOptions::default());
let code = code_block("println!(\"hi\");", Some("rust"), CodeBlockOptions::default());list(items, ListOptions)renders an ordered or unordered list. Usemarker: Some("- [ ]")for task-list markers.table(columns, rows)renders a Markdown table. Columns and cells can be borrowed strings or ownedStringvalues.
MIT. See LICENSE.