umark-lib 0.2.0

A Markdown Parser written in rust
Documentation
  • Coverage
  • 100%
    12 out of 12 items documented9 out of 10 items with examples
  • Size
  • Source code size: 65.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.65 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Synth1105

umark

umark is a Rust Markdown parser workspace with:

  • umark-lib: the parsing library
  • umark: a small CLI wrapper

The default parsing mode is GitHub Flavored Markdown (GFM).

Features

  • CommonMark-style core parsing
  • GFM extensions: tables, task lists, strikethrough, literal autolinks (https://..., www..., emails), footnotes, Mermaid fenced chart blocks (```mermaid), reference links ([label]: https://...), and ordered list start values (3. item)
  • Raw HTML passthrough in regular mode
  • Safe parsing mode that rejects script tags and raw HTML

Project Layout

  • umark-lib/src/lib.rs: parser implementation and public API
  • umark/src/main.rs: CLI entrypoint

Build

cargo build

CLI Usage

umark <input.md> <output.html> [--flavor gfm|commonmark] [--safe]

Examples:

# Default GFM parsing
umark README.md README.html

# CommonMark mode
umark README.md README-commonmark.html --flavor commonmark

# Safe mode (rejects raw HTML and script tags)
umark -- README.md README-safe.html --safe

Library Usage

Parse a Markdown string

use umark_lib::parse;

let html = parse("# Hello");
assert!(html.contains("<h1>Hello</h1>"));

Choose parsing flavor

use umark_lib::{parse_with_flavor, MarkdownFlavor};

let gfm = parse_with_flavor("~~done~~", MarkdownFlavor::Gfm);
let commonmark = parse_with_flavor("~~done~~", MarkdownFlavor::CommonMark);

assert!(gfm.contains("<del>done</del>"));
assert!(!commonmark.contains("<del>done</del>"));

Safe parsing

use umark_lib::safe_parse;

assert!(safe_parse("normal text").is_ok());
assert!(safe_parse("<script>alert(1)</script>").is_err());
assert!(safe_parse("x <span>raw html</span>").is_err());

Parse from file

use umark_lib::parse_from_file;

parse_from_file("input.md", "output.html")?;
# Ok::<(), Box<dyn std::error::Error>>(())

Parse from file in safe mode

use umark_lib::safe_parse_from_file;

safe_parse_from_file("input.md", "output.html")?;
# Ok::<(), Box<dyn std::error::Error>>(())

Mermaid Chart Support

In GFM mode:

```mermaid
flowchart TD
  A --> B
```

is rendered as:

<pre class="mermaid">flowchart TD
  A --&gt; B</pre>

When using parse_from_file* in GFM mode and Mermaid blocks are present, a Mermaid runtime script is automatically appended to the output HTML so charts render in a browser.

Safety Notes

  • safe_parse* rejects any raw HTML and script tags.
  • parse* allows raw HTML passthrough.
  • Safe mode is stricter by design and may reject content that regular parsing accepts.