1 unstable release
Uses new Rust 2024
| new 0.1.0 | Jan 6, 2026 |
|---|
#4 in #generate-html
19KB
196 lines
Markdown-to-HTML Converter (Rust)
A simple command-line tool written in Rust that converts Markdown files into HTML files. It uses pulldown-cmark for parsing and supports building an entire directory of Markdown files into a corresponding set of HTML outputs.
Features
- Recursive collection of Markdown files from an input directory
- Conversion from
.mdto.htmlusingpulldown-cmark. - Automatic output directory creation.
- Optional clean build.
- Simple, type-safe CLI built with
clap. - Extendable build pipeline suitable for static-site workflows.
- Access generated
.htmlfiles through localhost withservecommannd.
Installation
Clone the repository and build the project:
git clone https://github.com/Niall-Sharma/mkweb.git
cd <project-directory>
cargo build --release
The compiled binary will appear in target/release/.
Usage
Basic build
Convert an entire Markdown directory into HTML:
./mkweb --input ./notes
Specify an output directory
./mkweb --input ./notes --output ./public
Clean output directory before building
./mkweb --input ./notes --output ./public --clean
CLI Options
| Flag / Option | Description |
|---|---|
-i, --input |
Path to the directory containing Markdown files |
-o, --output |
Output directory for generated HTML (default: public) |
--clean |
Remove the output directory before generating files |
build |
Run the build pipeline |
serve |
Serve the generated files using localhost |
Example full command:
mkweb --input ./content --output ./site build
Project Structure
src/
main.rs # CLI + command routing
builder.rs # Directory scanning and file operations
parser.rs # Markdown → HTML conversion logic
How It Works
-
Collect Markdown files:
The program walks the input directory and finds all files ending in.md. -
Parse Markdown:
Each file’s contents are fed intopulldown-cmark::Parser. -
Generate HTML:
The converted HTML is written into a corresponding.htmlfile in the output directory. -
Output result:
If--cleanis passed, the output directory is recreated fresh before writing.
Requirements
- Rust 1.70+ (recommended)
- macOS, Linux, or Windows
Future Improvements
- Checkbox support
- Table support
- Front-matter parsing (YAML/JSON)
License
MIT License. See LICENSE for details.
Dependencies
~16MB
~207K SLoC