mirror of
https://github.com/Warky-Devs/go-mdtopdf-helper.git
synced 2025-05-18 15:17:29 +00:00
3.0 KiB
3.0 KiB
go-mdtopdf-helper
A command-line tool that automatically converts Markdown files to PDF using wkhtmltopdf. Perfect for maintaining PDF documentation alongside your Markdown files in Git repositories.
Features
- Converts Markdown files to high-quality PDFs
- Can run as a Git pre-commit hook
- Recursive directory scanning
- Parallel file processing
- Cross-platform support (Windows, Linux, macOS)
- Automatic detection of wkhtmltopdf installation
Prerequisites
This tool requires wkhtmltopdf to be installed on your system. The application will check for its presence in standard installation locations:
- Windows:
C:\Program Files\wkhtmltopdf\bin
- Linux:
/usr/local/bin/wkhtmltopdf
or/usr/bin/wkhtmltopdf
- macOS:
/usr/local/bin/wkhtmltopdf
or via Homebrew
If wkhtmltopdf is not found, you will be prompted to install it.
Installation
go get github.com/Warky-Devs/go-mdtopdf-helper
Usage
Basic Usage
Convert Markdown files in the current directory:
go-mdtopdf-helper
Command Line Options
go-mdtopdf-helper [options]
Options:
-dir string
Directory to scan for markdown files (default ".")
-recursive
Scan directories recursively (default true)
-parallel
Convert files in parallel (default true)
-hook
Run as git pre-commit hook
Git Pre-commit Hook
To use as a Git pre-commit hook:
- Create a file named
pre-commit
in your repository's.git/hooks/
directory - Add the following content:
#!/bin/sh
go-mdtopdf-helper -hook
- Make the hook executable:
chmod +x .git/hooks/pre-commit
When enabled as a pre-commit hook, the tool will:
- Detect staged Markdown files
- Ask for confirmation before conversion
- Convert files to PDF
- Automatically stage the generated PDFs
PDF Output Configuration
The generated PDFs are configured with:
- 300 DPI resolution
- 15mm margins on all sides
- Local file access enabled for images
- Support for common Markdown extensions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Development Setup
- Clone the repository
- Install dependencies:
go mod download
- Make your changes
- Run tests:
go test ./...
Dependencies
- go-wkhtmltopdf - Go wrapper for wkhtmltopdf
- gomarkdown - Markdown parser and HTML renderer
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to SebastiaanKlippert for the go-wkhtmltopdf library
- Thanks to the gomarkdown team for their Markdown parser