|
| 1 | +# Mermaid Converter CLI |
| 2 | + |
| 3 | +> Convert Markdown files with Mermaid diagrams to PDF and other formats from the command line |
| 4 | +
|
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install -g @mermaid-converter/cli |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```bash |
| 14 | +# Convert a single file |
| 15 | +mermaid-convert document.md |
| 16 | + |
| 17 | +# Convert with a specific template |
| 18 | +mermaid-convert document.md -t report -o professional-report.pdf |
| 19 | + |
| 20 | +# Convert multiple files |
| 21 | +mermaid-convert docs/*.md --batch -d output/ |
| 22 | + |
| 23 | +# Watch for changes |
| 24 | +mermaid-convert watch docs/ |
| 25 | +``` |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +- 🚀 **Fast conversions** with high-quality Mermaid diagram rendering |
| 30 | +- 📋 **6 built-in templates** for different use cases |
| 31 | +- 📦 **Batch processing** with progress bars and concurrent conversions |
| 32 | +- 👁️ **Watch mode** for automatic conversion on file changes |
| 33 | +- ⚙️ **Configurable** with project-level configuration files |
| 34 | +- 🎨 **Professional output** with customizable formatting options |
| 35 | + |
| 36 | +## Commands |
| 37 | + |
| 38 | +### `convert` - Convert Markdown files |
| 39 | + |
| 40 | +Convert one or more Markdown files to PDF (or other formats). |
| 41 | + |
| 42 | +```bash |
| 43 | +mermaid-convert convert input.md [options] |
| 44 | +``` |
| 45 | + |
| 46 | +**Options:** |
| 47 | +- `-f, --format <format>` - Output format (default: pdf) |
| 48 | +- `-o, --output <file>` - Output file (single file mode) |
| 49 | +- `-d, --output-dir <dir>` - Output directory (batch mode) |
| 50 | +- `-t, --template <name>` - Template to use (default: default) |
| 51 | +- `-b, --batch` - Enable batch processing for multiple files |
| 52 | +- `-c, --concurrency <n>` - Number of concurrent conversions (default: 3) |
| 53 | +- `--overwrite` - Overwrite existing files |
| 54 | + |
| 55 | +**Examples:** |
| 56 | +```bash |
| 57 | +# Basic conversion |
| 58 | +mermaid-convert convert README.md |
| 59 | + |
| 60 | +# Use specific template and output location |
| 61 | +mermaid-convert convert docs/guide.md -t presentation -o slides.pdf |
| 62 | + |
| 63 | +# Batch convert with custom settings |
| 64 | +mermaid-convert convert docs/*.md --batch -d output -t report -c 5 |
| 65 | + |
| 66 | +# Convert multiple files with glob pattern |
| 67 | +mermaid-convert convert "src/**/*.md" --batch -d dist/ |
| 68 | +``` |
| 69 | + |
| 70 | +### `watch` - Monitor files for changes |
| 71 | + |
| 72 | +Watch Markdown files and automatically convert them when they change. |
| 73 | + |
| 74 | +```bash |
| 75 | +mermaid-convert watch <path> [options] |
| 76 | +``` |
| 77 | + |
| 78 | +**Options:** |
| 79 | +- `-f, --format <format>` - Output format (default: pdf) |
| 80 | +- `-d, --output-dir <dir>` - Output directory (default: current) |
| 81 | +- `-t, --template <name>` - Template to use (default: default) |
| 82 | +- `-i, --ignore <pattern>` - Ignore pattern (default: node_modules/**) |
| 83 | +- `--debounce <ms>` - Debounce delay in milliseconds (default: 300) |
| 84 | + |
| 85 | +**Examples:** |
| 86 | +```bash |
| 87 | +# Watch current directory |
| 88 | +mermaid-convert watch . |
| 89 | + |
| 90 | +# Watch specific directory with custom template |
| 91 | +mermaid-convert watch docs/ -t documentation -d output/ |
| 92 | + |
| 93 | +# Watch with custom ignore patterns |
| 94 | +mermaid-convert watch . -i "*.tmp,node_modules/**,dist/**" |
| 95 | +``` |
| 96 | + |
| 97 | +### `templates` - Manage templates |
| 98 | + |
| 99 | +List and inspect available conversion templates. |
| 100 | + |
| 101 | +```bash |
| 102 | +mermaid-convert templates [options] |
| 103 | +``` |
| 104 | + |
| 105 | +**Options:** |
| 106 | +- `-l, --list` - List all available templates (default) |
| 107 | +- `-s, --show <name>` - Show details for a specific template |
| 108 | +- `-i, --interactive` - Interactive template selection |
| 109 | + |
| 110 | +**Examples:** |
| 111 | +```bash |
| 112 | +# List all templates |
| 113 | +mermaid-convert templates |
| 114 | + |
| 115 | +# Show template details |
| 116 | +mermaid-convert templates --show report |
| 117 | + |
| 118 | +# Interactive template browser |
| 119 | +mermaid-convert templates --interactive |
| 120 | +``` |
| 121 | + |
| 122 | +### `config` - Configuration management |
| 123 | + |
| 124 | +Create and manage CLI configuration files. |
| 125 | + |
| 126 | +```bash |
| 127 | +mermaid-convert config [options] |
| 128 | +``` |
| 129 | + |
| 130 | +**Options:** |
| 131 | +- `-i, --init` - Create a new configuration file |
| 132 | +- `-s, --show` - Show current configuration |
| 133 | +- `-p, --path` - Show configuration file path |
| 134 | + |
| 135 | +**Examples:** |
| 136 | +```bash |
| 137 | +# Create configuration file |
| 138 | +mermaid-convert config --init |
| 139 | + |
| 140 | +# Show current config |
| 141 | +mermaid-convert config --show |
| 142 | +``` |
| 143 | + |
| 144 | +## Templates |
| 145 | + |
| 146 | +The CLI comes with 6 built-in templates: |
| 147 | + |
| 148 | +| Template | Description | Use Case | |
| 149 | +|----------|-------------|----------| |
| 150 | +| `default` | Standard PDF with professional formatting | General documents | |
| 151 | +| `report` | High-quality with generous margins | Business reports | |
| 152 | +| `presentation` | Landscape format for slides | Presentations | |
| 153 | +| `documentation` | Optimized for technical docs | API docs, guides | |
| 154 | +| `dark` | Dark theme for code/diagrams | Developer documentation | |
| 155 | +| `compact` | Minimal margins for maximum content | Reference materials | |
| 156 | + |
| 157 | +### Template Options |
| 158 | + |
| 159 | +Each template includes settings for: |
| 160 | +- **Quality**: draft, standard, high |
| 161 | +- **Theme**: light, dark |
| 162 | +- **Page Size**: A4, Letter, Legal |
| 163 | +- **Margins**: Customizable spacing |
| 164 | +- **Orientation**: Portrait or landscape |
| 165 | + |
| 166 | +## Configuration |
| 167 | + |
| 168 | +Create a `.mermaid-convertrc.json` file in your project root: |
| 169 | + |
| 170 | +```json |
| 171 | +{ |
| 172 | + "defaultFormat": "pdf", |
| 173 | + "defaultTemplate": "documentation", |
| 174 | + "outputDirectory": "./dist", |
| 175 | + "overwrite": false, |
| 176 | + "concurrency": 3, |
| 177 | + "templates": { |
| 178 | + "custom": { |
| 179 | + "description": "My custom template", |
| 180 | + "options": { |
| 181 | + "quality": "high", |
| 182 | + "theme": "light", |
| 183 | + "margins": { |
| 184 | + "top": "30mm", |
| 185 | + "bottom": "30mm" |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +## Examples |
| 194 | + |
| 195 | +### Basic Usage |
| 196 | + |
| 197 | +```bash |
| 198 | +# Convert single file |
| 199 | +mermaid-convert convert documentation.md |
| 200 | + |
| 201 | +# Use professional template |
| 202 | +mermaid-convert convert report.md -t report |
| 203 | +``` |
| 204 | + |
| 205 | +### Batch Processing |
| 206 | + |
| 207 | +```bash |
| 208 | +# Convert all markdown files in docs/ |
| 209 | +mermaid-convert convert docs/*.md --batch -d output/ |
| 210 | + |
| 211 | +# Process with 5 concurrent conversions |
| 212 | +mermaid-convert convert docs/**/*.md --batch -c 5 |
| 213 | +``` |
| 214 | + |
| 215 | +### Development Workflow |
| 216 | + |
| 217 | +```bash |
| 218 | +# Watch for changes during development |
| 219 | +mermaid-convert watch docs/ -t documentation -d dist/ |
| 220 | + |
| 221 | +# Convert on save with custom debounce |
| 222 | +mermaid-convert watch . --debounce 1000 |
| 223 | +``` |
| 224 | + |
| 225 | +### Advanced Usage |
| 226 | + |
| 227 | +```bash |
| 228 | +# Custom output location and template |
| 229 | +mermaid-convert convert api.md -t presentation -o slides/api-overview.pdf |
| 230 | + |
| 231 | +# Batch with overwrite enabled |
| 232 | +mermaid-convert convert docs/*.md --batch --overwrite -d output/ |
| 233 | +``` |
| 234 | + |
| 235 | +## Global Options |
| 236 | + |
| 237 | +Available for all commands: |
| 238 | + |
| 239 | +- `-q, --quiet` - Suppress non-error output |
| 240 | +- `-v, --verbose` - Enable verbose logging |
| 241 | +- `--no-color` - Disable colored output |
| 242 | + |
| 243 | +## Output |
| 244 | + |
| 245 | +### Success Messages |
| 246 | +- ✅ File conversion progress and results |
| 247 | +- 📊 Processing statistics (file size, duration) |
| 248 | +- 📁 Output file locations |
| 249 | + |
| 250 | +### Error Handling |
| 251 | +- ❌ Clear error messages with suggestions |
| 252 | +- 🐛 Verbose mode for debugging |
| 253 | +- 📝 Automatic error logging to files |
| 254 | + |
| 255 | +## Troubleshooting |
| 256 | + |
| 257 | +### Common Issues |
| 258 | + |
| 259 | +**"No files found"** |
| 260 | +- Check your glob pattern syntax |
| 261 | +- Ensure Markdown files have `.md` extension |
| 262 | +- Use absolute paths if relative paths aren't working |
| 263 | + |
| 264 | +**"Diagram render failed"** |
| 265 | +- Verify Mermaid syntax is valid |
| 266 | +- Check for special characters in diagrams |
| 267 | +- Try with `--verbose` for detailed error information |
| 268 | + |
| 269 | +**"Permission denied"** |
| 270 | +- Ensure write permissions for output directory |
| 271 | +- Use `--overwrite` to replace existing files |
| 272 | + |
| 273 | +### Debug Mode |
| 274 | + |
| 275 | +```bash |
| 276 | +# Enable verbose logging |
| 277 | +mermaid-convert convert file.md --verbose |
| 278 | + |
| 279 | +# Check log files |
| 280 | +cat mermaid-convert.log |
| 281 | +cat mermaid-convert-error.log |
| 282 | +``` |
| 283 | + |
| 284 | +## License |
| 285 | + |
| 286 | +MIT License - see LICENSE file for details |
| 287 | + |
| 288 | +## Contributing |
| 289 | + |
| 290 | +1. Fork the repository |
| 291 | +2. Create a feature branch |
| 292 | +3. Make your changes |
| 293 | +4. Add tests if applicable |
| 294 | +5. Submit a pull request |
| 295 | + |
| 296 | +## Related Packages |
| 297 | + |
| 298 | +- `@mermaid-converter/core` - Core conversion library |
| 299 | +- `@mermaid-converter/mcp-server` - MCP server for Claude Desktop integration |
0 commit comments