10 releases
Uses new Rust 2024
new 0.1.9 | Apr 21, 2025 |
---|---|
0.1.8 | Apr 21, 2025 |
#1392 in Command line utilities
997 downloads per month
42KB
902 lines
๐ฆ Markdown to Rust Project Generator
This tool parses specially formatted Markdown files to generate fully structured Rust projects โ and even executes them (via cargo run
or cargo test
depending on the code)!
It can also extract a real Rust project from disk into a Markdown spec file using the extract
command!
๐ฆ What It Does
This CLI tool supports two main workflows:
๐ 1. Project Generation
- Scans all Markdown (
.md
) files in the current directory - Extracts embedded Rust code annotated with file paths
- Generates full Rust projects (files, folders,
Cargo.toml
, etc.) - Builds and runs
main.rs
projects usingcargo run
- Tests
lib.rs
projects usingcargo test
- Saves execution output to
run_output.log
ortest_output.log
๐ค 2. Project Extraction
- Takes an existing Rust codebase and generates a single Markdown file
- All
.rs
files are converted to annotated code blocks with file paths - Supports
.gitignore
and additional--skip
rules - Great for documentation, LLM prompts, or reproducible specs
๐ง Supported Markdown Formats
You can annotate code blocks in your Markdown using several supported patterns:
โ Supported Patterns
-
XML-style tag
<code path="src/main.rs"> fn main() { println!("Hello!"); } </code>
-
Markdown heading
### src/lib.rs ```rust pub fn add(a: i32, b: i32) -> i32 { a + b }
-
Delimiter marker
======== src/utils.rs ======== ```rust pub fn double(x: i32) -> i32 { x * 2 }
-
Raw comment before code
// file: src/math.rs pub fn square(x: i32) -> i32 { x * x }
-
File Fence
### <file> src/main.rs </file> ```rust use std::sync::Arc; use std::error::Error; use std::future::Future;
๐ Getting Started
๐ Prerequisites
- Rust & Cargo installed (
https://rustup.rs
)
๐ฅ Installation
cargo install prk_mdgen
๐งช Usage
๐ Markdown โ Rust (Default Mode)
prk_mdgen
Generate Rust projects from all .md
files in the current directory.
๐ค Extract Rust โ Markdown
prk_mdgen extract -o ./docs --skip target,.git,tests
This will scan the current Rust project and generate docs/codebase.md
with annotated code blocks for each file.
๐ง Additional CLI Options
USAGE:
prk_mdgen [OPTIONS]
OPTIONS:
-o, --output-dir <DIR> Output directory [default: output]
-p, --pattern <PATTERN> Force a specific pattern (code-tag, hash, delimiter, raw, file-code, file-fence)
-c, --command <COMMAND> sample | prompt | extract
-e, --execute Run `cargo run` or `cargo test` on generated projects
--skip <ITEMS> Comma-separated list of files or folders to skip
--project-type <TYPE> (Optional) Language hint during extraction (e.g. rust, node, flutter)
๐ Example Workflows
# Generate a prompt template
prk_mdgen prompt
# Generate sample Markdown to test parsing
prk_mdgen sample
# Extract an existing Rust project to Markdown
prk_mdgen extract -o ./docs --skip target,.git
# Generate projects from Markdown and run them
prk_mdgen -o ./output -e
๐ Output Structure
When generating a project from Markdown:
output/
โโโ my_project/
โโโ Cargo.toml
โโโ src/
โ โโโ main.rs
โโโ run_output.log # if main.rs exists
When extracting a project to Markdown:
output/
โโโ codebase.md # contains annotated code blocks for each source file
๐งช Execution Behavior
- If
src/main.rs
is present: runscargo run
, output is saved torun_output.log
- If
src/lib.rs
is present: runscargo test
, output is saved totest_output.log
๐ Development
To test parsing or generation logic:
prk_mdgen sample
To add new parsing formats, see parser.rs
and extend the MdPatternType
enum and detection logic.
๐งโ๐ป Contributing
Pull requests welcome! Please:
- Add a Markdown test case
- Use one or more supported code block patterns
- Run
cargo fmt
before committing
๐ชช License
MIT
โค๏ธ Made with Rust
This tool is built with love in Rust using:
Dependencies
~6โ15MB
~183K SLoC