marko

Crates.iomarko
lib.rsmarko
version0.3.0
sourcesrc
created_at2022-02-26 06:36:20.91474
updated_at2022-02-28 05:23:06.31242
descriptionProgrammtically format text with Markdown syntax
homepage
repositoryhttps://github.com/JosephTLyons/marko
max_upload_size
id539826
size48,605
Joseph T. Lyons (JosephTLyons)

documentation

README

marko

Programmtically format text with Markdown syntax, with marko!

use marko::{self, Markdown};
use std::collections::HashMap;

fn main() {
    let markdown_text = "Finish marko"
        .bold()
        .link("https://github.com/JosephTLyons/marko")
        .task(false);

    println!("{}", markdown_text);

    // - [ ] [**Finish marko**](https://github.com/JosephTLyons/marko)

    println!("{}", marko::divider());

    // ---

    let rows = [
        HashMap::from([
            ("Name", "Joseph"),
            ("Profession", "Developer"),
            ("Age", "31"),
            ("State", "Indiana"),
        ]),
        HashMap::from([
            ("Name", "Sam"),
            ("Profession", "Carpenter"),
            ("Age", "31"),
            ("State", "Arizona"),
        ]),
        HashMap::from([
            ("Name", "Seth"),
            ("Profession", "Fabricator"),
            ("Age", "30"),
            ("State", "Ohio"),
        ]),
        HashMap::from([
            ("Name", "Danny"),
            ("Profession", "Guitarist"),
            ("Age", "31"),
            ("State", "Indiana"),
        ]),
    ];

    let mut headers: Vec<_> = rows.first().unwrap().keys().cloned().collect();
    headers.sort();

    for row in marko::create_markdown_table(&headers, &rows) {
        println!("{row}");
    }

    // | Age | Name   | Profession | State   |
    // | --- | ------ | ---------- | ------- |
    // | 31  | Joseph | Developer  | Indiana |
    // | 31  | Sam    | Carpenter  | Arizona |
    // | 30  | Seth   | Fabricator | Ohio    |
    // | 31  | Danny  | Guitarist  | Indiana |
}
Commit count: 64

cargo fmt