MD to PDF helper in Go
Go to file
2024-12-07 12:23:10 +02:00
.github/workflows Workflow fixes 2024-12-07 12:23:10 +02:00
examples/dot.git/hooks Port from pv repo 2024-12-07 11:46:52 +02:00
.gitignore Initial commit 2024-12-07 11:34:06 +02:00
.goreleaser.yml Workflow fixes 2024-12-07 12:23:10 +02:00
converter_test.go Added test and releasing v1 2024-12-07 11:52:13 +02:00
go.mod Port from pv repo 2024-12-07 11:46:52 +02:00
go.sum Port from pv repo 2024-12-07 11:46:52 +02:00
LICENSE Initial commit 2024-12-07 11:34:06 +02:00
main.go Updated os issues and release conf 2024-12-07 12:13:43 +02:00
README.md Port from pv repo 2024-12-07 11:46:52 +02:00
README.pdf Updated os issues and release conf 2024-12-07 12:13:43 +02:00

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:

  1. Create a file named pre-commit in your repository's .git/hooks/ directory
  2. Add the following content:
#!/bin/sh
go-mdtopdf-helper -hook
  1. Make the hook executable:
chmod +x .git/hooks/pre-commit

When enabled as a pre-commit hook, the tool will:

  1. Detect staged Markdown files
  2. Ask for confirmation before conversion
  3. Convert files to PDF
  4. 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:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Setup

  1. Clone the repository
  2. Install dependencies:
    go mod download
    
  3. Make your changes
  4. Run tests:
    go test ./...
    

Dependencies

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