Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mdkit

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.

Usage

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"
);

Methods

All helpers return String values.

Text and layout

  • 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.

Links, images, and code

  • link(url, text, LinkOptions) renders a Markdown link. Set external: true to render an HTML link with target="_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());

Lists and tables

  • list(items, ListOptions) renders an ordered or unordered list. Use marker: Some("- [ ]") for task-list markers.
  • table(columns, rows) renders a Markdown table. Columns and cells can be borrowed strings or owned String values.

License

MIT. See LICENSE.

About

Simple Markdown rendering utilities

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages