51 releases (stable)

1.4.3 Mar 1, 2025
1.2.13 Jan 30, 2025
1.2.10 Jul 15, 2024
1.2.4 Feb 27, 2024
0.5.1 Jan 6, 2024

#567 in Parser implementations

Download history 134/week @ 2024-11-20 161/week @ 2024-11-27 78/week @ 2024-12-04 119/week @ 2024-12-11 172/week @ 2024-12-18 26/week @ 2024-12-25 333/week @ 2025-01-01 93/week @ 2025-01-08 99/week @ 2025-01-15 122/week @ 2025-01-22 225/week @ 2025-01-29 289/week @ 2025-02-05 434/week @ 2025-02-12 1050/week @ 2025-02-19 1126/week @ 2025-02-26 324/week @ 2025-03-05

2,960 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

46KB
1K SLoC

mdka

HTML to Markdown (MD) converter written in Rust.

crates.io Documentation License Dependency Status

Summary

A kind of text manipulator named mdka. "ka" means "化 (か)" pointing to conversion.
Designed with in mind:

  • Fast speed
  • Low memory consumption
  • Easy usage

Usage

Development with Rust and cargo

Cargo.toml

[dependencies]
mdka = "1"

awesome.rs

use mdka::from_html

fn awesome_fn() {
    let input = r#"
<h1>heading 1</h1>
<p>Hello, world.</p>"#;
    let ret = from_html(input);
    println!("{}", ret);
    // # heading 1
    // 
    // Hello, world.
    // 
}

Executable

Assets in Releases offer executables for multiple platforms.

$ ./mdka <html-text>
converted-to-markdown-text will be printed

Executable help

$ ./mdka -h
Usage:
  -h, --help             : Help is shown.
  <html_text>            : Direct parameter is taken as HTML text to be converted. Either this or <html_filepath> is required.
  -i <html_filepath>     : Read HTML text from it. Optional.
  -o <markdown_filepath> : Write Markdown result to it. Optional.
  --overwrites           : Overwrite if Markdown file exists. Optional.

Examples:
  ./mdka "<p>Hello, world.</p>"
  ./mdka -i input.html
  ./mdka -o output.md "<p>Hello, world.</p>"
  ./mdka -i input.html -o output.md --overwrites

Python integration

Bindings for Python are supported. Python scripts can import this Rust library to use the functions.

Install:

$ pip install mdka

awesome.py

from mdka import md_from_html

print(md_from_html("<p>Hello, world.</p>"))
# Hello, world.
# 

More Python code examples with specs are here.

Acknowledgements

Depends on Servo's html5ever / markup5ever. Also, on PyO3's pyo3 / maturin on bindings for Python.

Dependencies

~1.4–7MB
~47K SLoC