6 releases (stable)

1.2.1 Sep 21, 2020
1.1.1 Sep 21, 2020
1.0.1 Sep 17, 2020
0.1.1 Sep 16, 2020
0.1.0 Sep 16, 2020

#578 in Encoding

Download history 1743/week @ 2023-10-24 6315/week @ 2023-10-31 6028/week @ 2023-11-07 5737/week @ 2023-11-14 4784/week @ 2023-11-21 7467/week @ 2023-11-28 7233/week @ 2023-12-05 5222/week @ 2023-12-12 5058/week @ 2023-12-19 2815/week @ 2023-12-26 6846/week @ 2024-01-02 9120/week @ 2024-01-09 11056/week @ 2024-01-16 11405/week @ 2024-01-23 10311/week @ 2024-01-30 8568/week @ 2024-02-06

42,088 downloads per month
Used in journal_entry

MIT license

34KB
960 lines

markdown-gen

Rust crate for generating Markdown files

Usage

let file = File::create("test.md").unwrap();
let mut md = Markdown::new(file);

md.write("Heading".heading(1)).unwrap();
md.write("Subheading".italic().heading(2)).unwrap();

md.write("bold".bold()).unwrap();

md.write("first paragraph").unwrap();
md.write(
    "Links: ".paragraph()
    .append("Rust".bold().link_to("https://rust-lang.org"))
    .append(", ")
    .append("Google".italic().link_to("https://google.com"))
).unwrap();

md.write(
    List::new(true)
        .title("numbered list")
        .item("item 1")
        .item("bold".bold())
        .item(
                List::new(false)
                    .title("nested bullet list")
                    .item(
                        "bold".bold()
                            .paragraph().append(
                            "italic".italic()
                        )
                    )
           )
).unwrap();

md.write("quote".quote()).unwrap();

This produces the following Markdown document

# Heading
## *Subheading*
**bold**

first paragraph

Links: [**Rust**](https://rust\-lang\.org), [*Google*](https://google\.com)

numbered list
   1. item 1
   1. **bold**
   1. nested bullet list
      * **bold***italic*
>quote

You can also generate Markdown to Vec<u8>:

let mut md = Markdown::new(Vec::new());

md.write("test".heading(1)).unwrap();

let vec = md.into_inner();
assert_eq!(String::from_utf8(vec).unwrap(), "# test\n");

No runtime deps