Git Product home page Git Product logo

md-bakery's Introduction

Markdown Bakery

CLI tool to bake your fresh and hot MD files

Install

You can install from crates.io using cargo:

cargo install md-bakery

Note: The command used to run the program after installing is mdbakery not md-bakery.

About

At least once in your Rust dev lifetime you wanted to make sure all code examples in your markdown files are up-to-date, correct and code is formated, but you couldn't make that done with already existing tools - fear not!

Markdown Bakery allows you to create markdown template files with rust code injected from source files using special code block:

# Content of `./src/main.rs`:

```rust: source
./src/main.rs
```

After language part you tell MD Bakery this code part has to inject source code from path specified inside the code block.

If you want to escape MD Bakery code blocks you can put ! in front of source (sadly we can't show it here since that would print double ! in the readme file you read right now, more about why later).

If you prefer to inject different parts of the code file instead of keeping each code snippet in separate files, all you have to do is to inject named source:

# Snippet A:

```rust: source @ snippet-a
./src/main.rs
```

# Snippet B:

```rust: source @ snippet-b
./src/main.rs
```

And then in your source file you specify named blocks of the code where snippets are located, using comments like this:

use std::collections::HashMap;

// [md-bakery: begin @ snippet-a]
#[derive(Debug)]
struct Foo {
    bar: HashMap<String, usize>,
}
// [md-bakery: end]

fn main() {
    // [md-bakery: begin @ snippet-b]
    let foo = Foo {
        bar: {
            let mut result = HashMap::new();
            result.insert("answer".to_owned(), 42);
            result
        },
    };

    println!("{:?}", foo);
    // [md-bakery: end]
}

And then all of that renders into:

# Snippet A:

```rust
#[derive(Debug)]
struct Foo {
    bar: HashMap<String, usize>,
}
```

# Snippet B:

```rust
let foo = Foo {
    bar: {
        let mut result = HashMap::new();
        result.insert("answer".to_owned(), 42);
        result
    },
};

println!("{:?}", foo);
```

Of course this readme file was baked too, you can see template sources in /examples folder! So to see how to escape MD Bakery code blocks go there and look it up yourself :D

Usage:

md-bakery 1.0.0
Patryk 'PsichiX' Budzynski <[email protected]>
Markdown Bakery CLI app

USAGE:
    mdbakery.exe [OPTIONS] --input <FILE> --output <FILE>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -i, --input <FILE>     Markdown template file name
    -o, --output <FILE>    Markdown generated file name
    -r, --root <FILE>      Source files root path

TODO:

  • Add exec code block variant that runs executable with parameters specified in block content, then put its stdout:

    ```bash: exec
    cargo run -- --help
    ```
    

md-bakery's People

Contributors

psichix avatar zicklag avatar

Stargazers

Amadeusine avatar Bob avatar  avatar Dan Knox avatar Joshua Melander avatar ebigram avatar Erlend Sogge Heggen avatar Max Brown avatar Jay avatar Oliver Marshall avatar muuk avatar Adam Thibert avatar Willi Kappler avatar chris m avatar Andrey Snow avatar iain maitland avatar Matthias avatar Zach Schuermann avatar  avatar Moritz Mœller avatar Genaro Camele avatar Mario Fleischhacker avatar Lucy avatar David Sauer avatar Jonathan Johnson avatar  avatar Yining avatar Amelia Clarke avatar Josiah Hilden avatar Jarek Samic avatar  avatar guim avatar ohmycloud avatar  avatar Noah Hüsser avatar Michael Harding avatar Muhammed Doğan avatar Bruce Wang avatar Christos Papadopoulos avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

alaric zicklag

md-bakery's Issues

Automatic indentation removal

Great project. I'm adopting it right now, and I have one suggestion for a feature. When using snippets that are completely indented, ie:

{
    // [md-bakery: begin @ snippet-b]
    let db =
        Storage::<Shape>::open_local("view-examples.pliantdb", &Configuration::default()).await?;
    // [md-bakery: end]
}

The baked markdown includes the preceding whitespace on the lines. I would prefer if it stripped identical whitespace when it's present on all of the snippet lines.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.