@dkothule/md2pdf 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +77 -151
  2. package/package.json +21 -1
package/README.md CHANGED
@@ -4,244 +4,170 @@
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
6
 
7
+ `@dkothule/md2pdf` is a Markdown to PDF CLI for macOS and Linux with first-class Mermaid support.
8
+ It keeps Mermaid diagrams sharp in PDF by rendering vector assets (SVG by default) and includes automatic fallback logic for Mermaid flowcharts/graphs when needed.
7
9
 
8
- ## Why this tool
10
+ ## Why md2pdf
9
11
 
10
- - Mermaid diagrams are rendered as SVG for PDF output by default, so diagrams stay crisp at any zoom level.
11
- - Uses a PDF-safe Mermaid renderer config by default (`flowchart.htmlLabels=false`) to preserve diagram text in PDFs.
12
- - Improves flowchart edge-label readability by forcing opaque label backgrounds (prevents line strike-through in PDF output).
13
- - Auto-fallback for flowchart/graph diagrams: if SVG uses `foreignObject` labels, md2pdf can render Mermaid PDF for that diagram to preserve node text.
14
- - Mermaid PDF rendering uses fit-to-content page bounds by default (`MERMAID_PDF_FIT=true`) so diagrams do not force full-page layout.
15
- - Works on macOS and Linux (CLI).
16
- - macOS Finder Quick Action support for right-click conversion.
17
- - Configurable defaults via config file (PDF engine, margins, temp asset behavior, more).
18
- - Cleans Mermaid temp assets by default after conversion.
19
-
20
- ## Package layout
21
-
22
- - `bin/`: user-facing CLI commands (`md2pdf`, Finder Quick Action installers).
23
- - `lib/`: internal runtime helpers (Pandoc Mermaid filter + wrapper).
24
- - `assets/`: bundled static assets (`table-style.tex`, `mermaid.config.json`).
25
- - `scripts/`: helper scripts exposed as secondary commands.
26
- - `tests/`: repo-only smoke tests and Mermaid samples (not published to npm).
27
-
28
- ## Platform support
29
-
30
- - macOS: fully supported (CLI + Finder Quick Action).
31
- - Linux: supported for CLI conversion.
32
- - Finder context menu integration: macOS only.
12
+ - Markdown to PDF from the terminal.
13
+ - Mermaid to PDF with high-resolution vector rendering.
14
+ - SVG-first pipeline for crisp diagrams at any zoom level.
15
+ - Auto fallback to Mermaid PDF for diagrams that use `foreignObject` labels.
16
+ - Fit-to-content PDF fallback (`--pdfFit`) to avoid full-page diagram artifacts.
17
+ - Better edge-label readability in flowchart/graph diagrams.
18
+ - Configurable defaults (`~/.config/md2pdf/config.env`, project `.md2pdfrc`, or `--config`).
19
+ - Optional Finder Quick Action integration on macOS.
33
20
 
34
21
  ## Install
35
22
 
36
23
  ### 1) Install system dependencies
37
24
 
38
- From repo checkout:
25
+ From repo checkout, install required tools:
39
26
 
40
27
  ```bash
41
28
  ./install-system-deps.sh
42
29
  ```
43
30
 
44
- You need:
31
+ ### 2) Install md2pdf CLI
32
+
33
+ ```bash
34
+ npm i -g @dkothule/md2pdf
35
+ python3 -m pip install pandocfilters
36
+ ```
37
+
38
+ ## System requirements
39
+
45
40
  - `pandoc`
46
- - a PDF engine (`xelatex` by default)
41
+ - LaTeX PDF engine (`xelatex` default)
47
42
  - `librsvg` / `rsvg-convert`
48
- - `node` + `npm`
49
43
  - `python3`
50
- - Python package: `pandocfilters`
44
+ - `node` + `npm`
51
45
 
52
- ### 2) Install md2pdf
46
+ ## macOS Finder Quick Action (Optional)
53
47
 
54
- Global npm install:
48
+ Install Finder context menu action:
55
49
 
56
50
  ```bash
57
- npm i -g @dkothule/md2pdf
58
- python3 -m pip install pandocfilters
51
+ md2pdf-install-finder-action
59
52
  ```
60
53
 
61
- Repo-local setup:
54
+ Uninstall Finder context menu action:
62
55
 
63
56
  ```bash
64
- ./setup-local-deps.sh
57
+ md2pdf-uninstall-finder-action
65
58
  ```
66
59
 
67
- ## First conversion
60
+ If Finder menu does not refresh immediately:
68
61
 
69
62
  ```bash
70
- md2pdf /path/to/file.md
63
+ killall Finder
71
64
  ```
72
65
 
73
- Output defaults to `/path/to/file.pdf`.
66
+ After installation, right-click any `.md` file in Finder:
67
+
68
+ `Quick Actions` -> `Convert Markdown to PDF`
69
+
70
+ ![Finder Quick Action menu](docs/images/finder-quick-action.png)
71
+
72
+ ## Quick start
74
73
 
75
- Custom output:
74
+ Convert Markdown to PDF (output goes beside input by default):
76
75
 
77
76
  ```bash
78
- md2pdf /path/to/file.md -o /path/to/output.pdf
77
+ md2pdf ./notes.md
79
78
  ```
80
79
 
81
- ## CLI options
80
+ Custom output path:
82
81
 
83
82
  ```bash
84
- md2pdf --help
85
- md2pdf --version
86
- md2pdf --init
87
- md2pdf --init /path/to/config.env --force
83
+ md2pdf ./notes.md -o ./build/notes.pdf
88
84
  ```
89
85
 
90
- ## Where npm installs it
86
+ Keep generated Mermaid assets for debugging:
91
87
 
92
- For global install (`npm i -g @dkothule/md2pdf`):
88
+ ```bash
89
+ md2pdf ./notes.md --keep-mermaid-assets
90
+ ```
93
91
 
94
- - package files: `$(npm prefix -g)/lib/node_modules/@dkothule/md2pdf`
95
- - executable command: `$(npm prefix -g)/bin/md2pdf`
92
+ ## Mermaid support details
96
93
 
97
- For local project install:
94
+ md2pdf uses:
98
95
 
99
- - package files: `./node_modules/@dkothule/md2pdf`
100
- - executable shim: `./node_modules/.bin/md2pdf`
96
+ - `MERMAID_LATEX_FORMAT=svg` by default for vector quality in PDF.
97
+ - `MERMAID_AUTO_PDF_FALLBACK=true` by default to preserve flowchart/graph node labels when SVG uses `foreignObject`.
98
+ - `MERMAID_PDF_FIT=true` by default so Mermaid PDF fallback assets use tight bounds and do not force one-diagram-per-page.
101
99
 
102
100
  ## Configuration
103
101
 
104
- `md2pdf` loads config in this order (later overrides earlier):
102
+ Config precedence (later overrides earlier):
105
103
 
106
104
  1. `$HOME/.config/md2pdf/config.env`
107
105
  2. `<input-markdown-directory>/.md2pdfrc`
108
106
  3. `--config /path/to/config.env`
109
- 4. environment variables
107
+ 4. Environment variables
110
108
 
111
- Initialize default config automatically:
109
+ Create starter config:
112
110
 
113
111
  ```bash
114
112
  md2pdf --init
115
113
  ```
116
114
 
117
- This creates:
118
-
119
- - `~/.config/md2pdf/config.env`
120
-
121
- Initialize to a custom path:
122
-
123
- ```bash
124
- md2pdf --init ./md2pdf.config.env
125
- ```
126
-
127
- If target file already exists, re-run with `--force` to overwrite.
128
-
129
- Manual template copy (optional):
130
-
131
- ```bash
132
- mkdir -p ~/.config/md2pdf
133
- cp ./md2pdf.config.example ~/.config/md2pdf/config.env
134
- ```
135
-
136
- If installed globally from npm, template path is:
115
+ Create starter config at custom path:
137
116
 
138
117
  ```bash
139
- $(npm root -g)/@dkothule/md2pdf/md2pdf.config.example
118
+ md2pdf --init ./md2pdf.config.env --force
140
119
  ```
141
120
 
142
121
  Example config:
143
122
 
144
123
  ```bash
145
124
  PDF_ENGINE=xelatex
146
- MERMAID_CONFIG=/absolute/path/to/mermaid.config.json
125
+ LR_MARGIN=0.7in
126
+ TB_MARGIN=0.5in
147
127
  MERMAID_LATEX_FORMAT=svg
148
128
  MERMAID_PDF_FIT=true
149
129
  MERMAID_AUTO_PDF_FALLBACK=true
150
- LR_MARGIN=0.7in
151
- TB_MARGIN=0.5in
152
130
  CLEANUP_MERMAID_ASSETS=true
153
131
  MERMAID_ASSET_PREFIX=md2pdf-mermaid
154
132
  ```
155
133
 
156
- Useful flags:
134
+ ## CLI reference
157
135
 
158
136
  ```bash
159
- md2pdf input.md --config ./my-config.env
160
- md2pdf input.md --keep-mermaid-assets
161
- md2pdf input.md --cleanup-mermaid-assets
162
- ```
163
-
164
- ## Mermaid temp assets
165
-
166
- When Mermaid blocks are present, md2pdf creates:
167
-
168
- - `<MERMAID_ASSET_PREFIX>-<run-id>-images/`
169
-
170
- By default, this folder is deleted after conversion (`CLEANUP_MERMAID_ASSETS=true`).
171
-
172
- ## macOS Finder Quick Action
173
-
174
- Install:
175
-
176
- ```bash
177
- md2pdf-install-finder-action
178
- ```
179
-
180
- Or from repo:
181
-
182
- ```bash
183
- ./scripts/install_md2pdf_quick_action.sh
184
- ```
185
-
186
- Use in Finder:
187
-
188
- - Right click `.md` file -> `Quick Actions` -> `Convert Markdown to PDF`
189
-
190
- Remove:
191
-
192
- ```bash
193
- md2pdf-uninstall-finder-action
194
- ```
195
-
196
- Or from repo:
197
-
198
- ```bash
199
- ./scripts/uninstall_md2pdf_quick_action.sh
137
+ md2pdf --help
138
+ md2pdf --version
139
+ md2pdf --init
200
140
  ```
201
141
 
202
- If menu entries do not refresh immediately:
142
+ Common options:
203
143
 
204
- ```bash
205
- killall Finder
206
- ```
144
+ - `-o, --output <file>`: output PDF path
145
+ - `--config <file>`: load additional config file
146
+ - `--keep-mermaid-assets`: keep generated Mermaid temp files
147
+ - `--cleanup-mermaid-assets`: remove generated Mermaid temp files (default)
207
148
 
208
- ## Architecture and test samples
149
+ ## Test samples
209
150
 
210
- - Architecture doc: `docs/ARCHITECTURE.md`
211
- - Smoke test markdown: `tests/architecture-smoke-test.md`
212
- - Mermaid all-diagram sample pack: `tests/samples/mermaid-all-diagram-types.md`
151
+ - Smoke test: `tests/architecture-smoke-test.md`
152
+ - Mermaid sample pack: `tests/samples/mermaid-all-diagram-types.md`
213
153
 
214
- Run demo:
154
+ Run:
215
155
 
216
156
  ```bash
217
157
  md2pdf ./tests/architecture-smoke-test.md
218
- ```
219
-
220
- Run the full Mermaid sample suite:
221
-
222
- ```bash
223
158
  md2pdf ./tests/samples/mermaid-all-diagram-types.md --keep-mermaid-assets
224
159
  ```
225
160
 
226
- ## Publish (maintainer)
227
-
228
- ```bash
229
- npm login
230
- npm pack --dry-run
231
- npm publish
232
- ```
161
+ ## Troubleshooting
233
162
 
234
- Package: `@dkothule/md2pdf`
163
+ - `mmdc not found`: install dependencies and verify `MERMAID_BIN`.
164
+ - Flowchart/graph labels missing in PDF: keep `MERMAID_AUTO_PDF_FALLBACK=true`.
165
+ - Diagram taking a full page: keep `MERMAID_PDF_FIT=true`.
166
+ - PDF engine missing: install `xelatex` or set `PDF_ENGINE`.
235
167
 
236
- ## Troubleshooting
168
+ ## Keywords
237
169
 
238
- - `mmdc not found`: install npm deps (`./setup-local-deps.sh`) or set `MERMAID_BIN`.
239
- - Flowchart/graph node labels missing in PDF: keep `MERMAID_AUTO_PDF_FALLBACK=true` (default) so affected SVG diagrams auto-fallback to Mermaid PDF per-diagram.
240
- - To force pure SVG only (disable fallback): set `MERMAID_AUTO_PDF_FALLBACK=false`.
241
- - Mermaid diagrams consuming a full page in output PDF: keep `MERMAID_PDF_FIT=true` (default) so Mermaid PDF assets use tight bounds.
242
- - Mermaid still generating `.svg` instead of `.pdf`: check `~/.config/md2pdf/config.env` and remove/adjust `MERMAID_LATEX_FORMAT=svg`.
243
- - PDF engine not found: install `xelatex` or set `PDF_ENGINE` to an installed engine.
244
- - Finder Quick Action not visible: run `killall Finder`.
170
+ markdown to pdf, md to pdf, mermaid to pdf, mermaid svg, pandoc markdown pdf, markdown pdf cli, macOS markdown pdf, Linux markdown pdf
245
171
 
246
172
  ## License
247
173
 
package/package.json CHANGED
@@ -1,9 +1,29 @@
1
1
  {
2
2
  "name": "@dkothule/md2pdf",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Markdown to PDF converter with high-resolution Mermaid diagram rendering",
5
5
  "author": "Deepak Kothule",
6
6
  "license": "MIT",
7
+ "keywords": [
8
+ "markdown",
9
+ "md",
10
+ "pdf",
11
+ "markdown-to-pdf",
12
+ "md2pdf",
13
+ "mermaid",
14
+ "mermaid-cli",
15
+ "pandoc",
16
+ "documentation",
17
+ "cli"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/dkothule/md2pdf.git"
22
+ },
23
+ "homepage": "https://github.com/dkothule/md2pdf#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/dkothule/md2pdf/issues"
26
+ },
7
27
  "publishConfig": {
8
28
  "access": "public"
9
29
  },