0f09b30164c1268839fee742faf1c52ed4182c9d
Introduce a Node.js CLI tool that converts Markdown files to styled
PDFs using `marked` for parsing and `puppeteer` for rendering.
- Add `md-to-pdf.js` as the main conversion script with:
- CLI argument handling for input/output file paths
- Automatic output directory creation alongside the input file
- Pre-processing to strip thematic breaks (`---`) before headings
- Embedded CSS for clean, print-ready styling (headings, tables,
code blocks, blockquotes, page breaks, etc.)
- PDF generation via Puppeteer with A4 format and custom margins
- Add `.gitignore` to exclude `node_modules/` and `output/` directories
- Add `package-lock.json` with resolved dependencies (marked, puppeteer)
markdown-to-pdf
Convertit un fichier Markdown en PDF bien mis en forme — fond blanc, typographie soignée, sans coupures de page au milieu des tableaux ou des blocs de code.
Installation
npm install
Utilisation
node md-to-pdf.js <fichier.md>
Le PDF est généré dans output/<fichier>.pdf, à côté du fichier source. Le dossier output/ est créé automatiquement s'il n'existe pas.
Un chemin de sortie personnalisé peut être fourni en second argument :
node md-to-pdf.js rapport.md /tmp/rapport.pdf
Fonctionnalités
- Tableaux, blocs de code, citations et images jamais coupés entre deux pages
- Les titres ne se retrouvent pas seuls en bas de page
- Lignes alternées sur les tableaux
- Code inline et en blocs avec police monospace et fond discret
- Citations avec bordure bleue à gauche
- Format A4 avec marges adaptées
Dépendances
| Package | Rôle |
|---|---|
marked |
Markdown → HTML |
puppeteer |
HTML → PDF via Chromium headless |
Description
Languages
JavaScript
100%