# MD-to-PDF

A powerful TypeScript CLI tool for converting Markdown files to beautifully formatted PDF documents with syntax highlighting.

## ✨ Features

- 📄 **Single file and batch conversion** - Convert individual files or entire directories
- 🎨 **GitHub-style styling** - Professional appearance like on GitHub
- 🌙 **Light & Dark Theme** - Selectable syntax highlighting (github-light, github-dark)
- 📑 **Automatic Table of Contents** - Generated from headings
- 📝 **Frontmatter support** - YAML metadata for title, author, date, etc.
- 📰 **Headers and Footers** - With automatic page numbering
- 🎯 **Configuration files** - Project-wide default settings
- 💅 **Custom CSS** - Add your own styles

## 🚀 Installation

```bash
# Install globally
bun add -g md-to-pdf

# Or locally in your project
bun add md-to-pdf
```

## 📖 Usage

### Simple Conversion

```bash
# Convert a single file
md-to-pdf document.md

# With output path
md-to-pdf document.md --output ./output/

# Use dark theme
md-to-pdf document.md --theme github-dark
```

### Batch Conversion

```bash
# Convert entire directory
md-to-pdf ./docs/

# Multiple files/directories
md-to-pdf file1.md file2.md ./more-docs/
```

### All Options

```bash
md-to-pdf [inputs...] [options]

Options:
  -o, --output <path>    Output path (file or directory)
  -t, --theme <theme>    Theme (github-light, github-dark)
  --toc                  Generate table of contents (default: on)
  --no-toc               Disable table of contents
  --header               Include header (default: on)
  --no-header            Disable header
  --footer               Include footer (default: on)
  --no-footer            Disable footer
  -f, --format <format>  Page format (A4, Letter, Legal, Tabloid)
  -c, --css <path>       Path to custom CSS file
  --config <path>        Path to configuration file
  -v, --verbose          Verbose output
  -q, --quiet            Only show errors
  -h, --help             Show help
  -V, --version          Show version
```

### Create Configuration File

```bash
md-to-pdf init
```

This creates a `md-to-pdf.config.json` with default settings:

```json
{
  "defaults": {
    "format": "A4",
    "theme": "github-light",
    "toc": true,
    "header": true,
    "footer": true,
    "margin": {
      "top": "20mm",
      "right": "20mm",
      "bottom": "20mm",
      "left": "20mm"
    }
  },
  "customCss": "/* Your custom styles here */"
}
```

## 📄 Frontmatter

Use YAML frontmatter at the beginning of your Markdown files:

```yaml
---
title: My Document
author: John Doe
date: 2024-12-09
description: A description
toc: true
theme: github-dark
---
```

### Supported Frontmatter Fields

| Field         | Type    | Description                     |
| ------------- | ------- | ------------------------------- |
| `title`       | string  | Document title                  |
| `author`      | string  | Author                          |
| `date`        | string  | Date                            |
| `description` | string  | Subtitle/description            |
| `toc`         | boolean | Table of contents on/off        |
| `theme`       | string  | `github-light` or `github-dark` |

## 🎨 Syntax Highlighting

The converter supports syntax highlighting for over 180 programming languages through [highlight.js](https://highlightjs.org/).

Popular languages:
- JavaScript/TypeScript
- Python
- Java
- C/C++
- Go
- Rust
- SQL
- HTML/CSS
- Bash
- and many more...

## 📦 Programmatic Usage

```typescript
import { Converter, PdfGenerator } from 'md-to-pdf';

// With Converter (recommended)
const converter = new Converter();
await converter.initialize();
await converter.convertFile('document.md', {
  theme: 'github-dark',
  toc: true
});
await converter.close();

// Or directly with PdfGenerator
const generator = new PdfGenerator();
await generator.initialize();
await generator.generateFromContent('# Hello\n\nWorld!', 'output.pdf');
await generator.close();
```

## 🛠️ Development

```bash
# Clone repository
git clone https://github.com/your-username/md-to-pdf.git
cd md-to-pdf

# Install dependencies
bun install

# Build
bun run build

# Develop in watch mode
bun run dev

# Run tests
bun test

# Run tests in watch mode
bun test --watch

# Run tests with coverage
bun test --coverage
```

## 📝 License

MIT License - see [LICENSE](LICENSE) for details.
