@dkothule/md2pdf 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/assets/mermaid.config.json +12 -0
- package/assets/table-style.tex +7 -0
- package/bin/md2pdf +510 -0
- package/docs/ARCHITECTURE.md +93 -0
- package/install-system-deps.sh +52 -0
- package/lib/pandoc_mermaid_filter.py +128 -0
- package/lib/run_pandoc_mermaid_filter.sh +7 -0
- package/md2pdf.config.example +54 -0
- package/package.json +36 -0
- package/requirements.txt +3 -0
- package/scripts/convert-md-to-pdf.sh +10 -0
- package/scripts/install_md2pdf_quick_action.sh +259 -0
- package/scripts/uninstall_md2pdf_quick_action.sh +24 -0
- package/setup-local-deps.sh +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Deepak Kothule
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# md2pdf
|
|
2
|
+
|
|
3
|
+
> Convert Markdown to PDF with high-resolution Mermaid diagrams (SVG embedded in PDF output).
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Why this tool
|
|
9
|
+
|
|
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.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
### 1) Install system dependencies
|
|
37
|
+
|
|
38
|
+
From repo checkout:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
./install-system-deps.sh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
You need:
|
|
45
|
+
- `pandoc`
|
|
46
|
+
- a PDF engine (`xelatex` by default)
|
|
47
|
+
- `librsvg` / `rsvg-convert`
|
|
48
|
+
- `node` + `npm`
|
|
49
|
+
- `python3`
|
|
50
|
+
- Python package: `pandocfilters`
|
|
51
|
+
|
|
52
|
+
### 2) Install md2pdf
|
|
53
|
+
|
|
54
|
+
Global npm install:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm i -g @dkothule/md2pdf
|
|
58
|
+
python3 -m pip install pandocfilters
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Repo-local setup:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
./setup-local-deps.sh
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## First conversion
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
md2pdf /path/to/file.md
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Output defaults to `/path/to/file.pdf`.
|
|
74
|
+
|
|
75
|
+
Custom output:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
md2pdf /path/to/file.md -o /path/to/output.pdf
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## CLI options
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
md2pdf --help
|
|
85
|
+
md2pdf --version
|
|
86
|
+
md2pdf --init
|
|
87
|
+
md2pdf --init /path/to/config.env --force
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Where npm installs it
|
|
91
|
+
|
|
92
|
+
For global install (`npm i -g @dkothule/md2pdf`):
|
|
93
|
+
|
|
94
|
+
- package files: `$(npm prefix -g)/lib/node_modules/@dkothule/md2pdf`
|
|
95
|
+
- executable command: `$(npm prefix -g)/bin/md2pdf`
|
|
96
|
+
|
|
97
|
+
For local project install:
|
|
98
|
+
|
|
99
|
+
- package files: `./node_modules/@dkothule/md2pdf`
|
|
100
|
+
- executable shim: `./node_modules/.bin/md2pdf`
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
`md2pdf` loads config in this order (later overrides earlier):
|
|
105
|
+
|
|
106
|
+
1. `$HOME/.config/md2pdf/config.env`
|
|
107
|
+
2. `<input-markdown-directory>/.md2pdfrc`
|
|
108
|
+
3. `--config /path/to/config.env`
|
|
109
|
+
4. environment variables
|
|
110
|
+
|
|
111
|
+
Initialize default config automatically:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
md2pdf --init
|
|
115
|
+
```
|
|
116
|
+
|
|
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:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
$(npm root -g)/@dkothule/md2pdf/md2pdf.config.example
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Example config:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
PDF_ENGINE=xelatex
|
|
146
|
+
MERMAID_CONFIG=/absolute/path/to/mermaid.config.json
|
|
147
|
+
MERMAID_LATEX_FORMAT=svg
|
|
148
|
+
MERMAID_PDF_FIT=true
|
|
149
|
+
MERMAID_AUTO_PDF_FALLBACK=true
|
|
150
|
+
LR_MARGIN=0.7in
|
|
151
|
+
TB_MARGIN=0.5in
|
|
152
|
+
CLEANUP_MERMAID_ASSETS=true
|
|
153
|
+
MERMAID_ASSET_PREFIX=md2pdf-mermaid
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Useful flags:
|
|
157
|
+
|
|
158
|
+
```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
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
If menu entries do not refresh immediately:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
killall Finder
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Architecture and test samples
|
|
209
|
+
|
|
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`
|
|
213
|
+
|
|
214
|
+
Run demo:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
md2pdf ./tests/architecture-smoke-test.md
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Run the full Mermaid sample suite:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
md2pdf ./tests/samples/mermaid-all-diagram-types.md --keep-mermaid-assets
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Publish (maintainer)
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
npm login
|
|
230
|
+
npm pack --dry-run
|
|
231
|
+
npm publish
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Package: `@dkothule/md2pdf`
|
|
235
|
+
|
|
236
|
+
## Troubleshooting
|
|
237
|
+
|
|
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`.
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT License, Copyright (c) 2026 Deepak Kothule
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"theme": "default",
|
|
3
|
+
"flowchart": {
|
|
4
|
+
"htmlLabels": false,
|
|
5
|
+
"markdownAutoWrap": false
|
|
6
|
+
},
|
|
7
|
+
"markdownAutoWrap": false,
|
|
8
|
+
"themeVariables": {
|
|
9
|
+
"edgeLabelBackground": "#ffffff"
|
|
10
|
+
},
|
|
11
|
+
"themeCSS": ".edgeLabel rect, .edgeLabel .background { fill: #ffffff !important; opacity: 1 !important; stroke: #ffffff !important; stroke-width: 1px !important; }"
|
|
12
|
+
}
|