@dkothule/md2pdf 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -4,244 +4,203 @@
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
- ### 1) Install system dependencies
37
-
38
- From repo checkout:
39
-
40
- ```bash
41
- ./install-system-deps.sh
42
- ```
23
+ ### Frictionless install (recommended)
43
24
 
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`
25
+ Prerequisite: Node.js + npm installed (required to install the npm package).
51
26
 
52
- ### 2) Install md2pdf
53
-
54
- Global npm install:
27
+ 1) Install md2pdf:
55
28
 
56
29
  ```bash
57
30
  npm i -g @dkothule/md2pdf
58
- python3 -m pip install pandocfilters
59
31
  ```
60
32
 
61
- Repo-local setup:
33
+ 2) Install runtime dependencies (system packages + `pandocfilters`):
62
34
 
63
35
  ```bash
64
- ./setup-local-deps.sh
36
+ md2pdf-install-system-deps
65
37
  ```
66
38
 
67
- ## First conversion
39
+ Use `--yes` to skip the confirmation prompt (helpful for automation):
68
40
 
69
41
  ```bash
70
- md2pdf /path/to/file.md
42
+ md2pdf-install-system-deps --yes
71
43
  ```
72
44
 
73
- Output defaults to `/path/to/file.pdf`.
74
-
75
- Custom output:
45
+ 3) Verify:
76
46
 
77
47
  ```bash
78
- md2pdf /path/to/file.md -o /path/to/output.pdf
79
- ```
80
-
81
- ## CLI options
82
-
83
- ```bash
84
- md2pdf --help
85
48
  md2pdf --version
86
- md2pdf --init
87
- md2pdf --init /path/to/config.env --force
49
+ md2pdf --help
88
50
  ```
89
51
 
90
- ## Where npm installs it
52
+ `md2pdf-install-system-deps` supports macOS (Homebrew) and Debian/Ubuntu.
53
+ Run `md2pdf-install-system-deps --help` to see options.
91
54
 
92
- For global install (`npm i -g @dkothule/md2pdf`):
55
+ ### Manual fallback (if helper script does not support your Linux distro)
93
56
 
94
- - package files: `$(npm prefix -g)/lib/node_modules/@dkothule/md2pdf`
95
- - executable command: `$(npm prefix -g)/bin/md2pdf`
57
+ Install these dependencies yourself:
96
58
 
97
- For local project install:
59
+ - `pandoc`
60
+ - LaTeX PDF engine (`xelatex` default)
61
+ - `librsvg` / `rsvg-convert`
62
+ - `python3` + `pip`
63
+ - `node` + `npm`
98
64
 
99
- - package files: `./node_modules/@dkothule/md2pdf`
100
- - executable shim: `./node_modules/.bin/md2pdf`
65
+ Then install the Python dependency:
101
66
 
102
- ## Configuration
67
+ ```bash
68
+ python3 -m pip install pandocfilters
69
+ ```
103
70
 
104
- `md2pdf` loads config in this order (later overrides earlier):
71
+ ## System requirements
105
72
 
106
- 1. `$HOME/.config/md2pdf/config.env`
107
- 2. `<input-markdown-directory>/.md2pdfrc`
108
- 3. `--config /path/to/config.env`
109
- 4. environment variables
73
+ - `pandoc`
74
+ - LaTeX PDF engine (`xelatex` default)
75
+ - `librsvg` / `rsvg-convert`
76
+ - `python3`
77
+ - `node` + `npm`
78
+
79
+ ## macOS Finder Quick Action (Optional)
110
80
 
111
- Initialize default config automatically:
81
+ Install Finder context menu action:
112
82
 
113
83
  ```bash
114
- md2pdf --init
84
+ md2pdf-install-finder-action
115
85
  ```
116
86
 
117
- This creates:
87
+ Uninstall Finder context menu action:
118
88
 
119
- - `~/.config/md2pdf/config.env`
89
+ ```bash
90
+ md2pdf-uninstall-finder-action
91
+ ```
120
92
 
121
- Initialize to a custom path:
93
+ If Finder menu does not refresh immediately:
122
94
 
123
95
  ```bash
124
- md2pdf --init ./md2pdf.config.env
96
+ killall Finder
125
97
  ```
126
98
 
127
- If target file already exists, re-run with `--force` to overwrite.
99
+ After installation, right-click any `.md` file in Finder:
128
100
 
129
- Manual template copy (optional):
101
+ `Quick Actions` -> `Convert Markdown to PDF`
130
102
 
131
- ```bash
132
- mkdir -p ~/.config/md2pdf
133
- cp ./md2pdf.config.example ~/.config/md2pdf/config.env
134
- ```
103
+ ![Finder Quick Action menu](docs/images/finder-quick-action.png)
135
104
 
136
- If installed globally from npm, template path is:
105
+ ## Quick start
106
+
107
+ Convert Markdown to PDF (output goes beside input by default):
137
108
 
138
109
  ```bash
139
- $(npm root -g)/@dkothule/md2pdf/md2pdf.config.example
110
+ md2pdf ./notes.md
140
111
  ```
141
112
 
142
- Example config:
113
+ Custom output path:
143
114
 
144
115
  ```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
116
+ md2pdf ./notes.md -o ./build/notes.pdf
154
117
  ```
155
118
 
156
- Useful flags:
119
+ Keep generated Mermaid assets for debugging:
157
120
 
158
121
  ```bash
159
- md2pdf input.md --config ./my-config.env
160
- md2pdf input.md --keep-mermaid-assets
161
- md2pdf input.md --cleanup-mermaid-assets
122
+ md2pdf ./notes.md --keep-mermaid-assets
162
123
  ```
163
124
 
164
- ## Mermaid temp assets
165
-
166
- When Mermaid blocks are present, md2pdf creates:
125
+ ## Mermaid support details
167
126
 
168
- - `<MERMAID_ASSET_PREFIX>-<run-id>-images/`
127
+ md2pdf uses:
169
128
 
170
- By default, this folder is deleted after conversion (`CLEANUP_MERMAID_ASSETS=true`).
129
+ - `MERMAID_LATEX_FORMAT=svg` by default for vector quality in PDF.
130
+ - `MERMAID_AUTO_PDF_FALLBACK=true` by default to preserve flowchart/graph node labels when SVG uses `foreignObject`.
131
+ - `MERMAID_PDF_FIT=true` by default so Mermaid PDF fallback assets use tight bounds and do not force one-diagram-per-page.
171
132
 
172
- ## macOS Finder Quick Action
133
+ ## Configuration
173
134
 
174
- Install:
135
+ Config precedence (later overrides earlier):
175
136
 
176
- ```bash
177
- md2pdf-install-finder-action
178
- ```
137
+ 1. `$HOME/.config/md2pdf/config.env`
138
+ 2. `<input-markdown-directory>/.md2pdfrc`
139
+ 3. `--config /path/to/config.env`
140
+ 4. Environment variables
179
141
 
180
- Or from repo:
142
+ Create starter config:
181
143
 
182
144
  ```bash
183
- ./scripts/install_md2pdf_quick_action.sh
145
+ md2pdf --init
184
146
  ```
185
147
 
186
- Use in Finder:
187
-
188
- - Right click `.md` file -> `Quick Actions` -> `Convert Markdown to PDF`
189
-
190
- Remove:
148
+ Create starter config at custom path:
191
149
 
192
150
  ```bash
193
- md2pdf-uninstall-finder-action
151
+ md2pdf --init ./md2pdf.config.env --force
194
152
  ```
195
153
 
196
- Or from repo:
154
+ Example config:
197
155
 
198
156
  ```bash
199
- ./scripts/uninstall_md2pdf_quick_action.sh
157
+ PDF_ENGINE=xelatex
158
+ LR_MARGIN=0.7in
159
+ TB_MARGIN=0.5in
160
+ MERMAID_LATEX_FORMAT=svg
161
+ MERMAID_PDF_FIT=true
162
+ MERMAID_AUTO_PDF_FALLBACK=true
163
+ CLEANUP_MERMAID_ASSETS=true
164
+ MERMAID_ASSET_PREFIX=md2pdf-mermaid
200
165
  ```
201
166
 
202
- If menu entries do not refresh immediately:
167
+ ## CLI reference
203
168
 
204
169
  ```bash
205
- killall Finder
170
+ md2pdf --help
171
+ md2pdf --version
172
+ md2pdf --init
206
173
  ```
207
174
 
208
- ## Architecture and test samples
175
+ Common options:
209
176
 
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`
177
+ - `-o, --output <file>`: output PDF path
178
+ - `--config <file>`: load additional config file
179
+ - `--keep-mermaid-assets`: keep generated Mermaid temp files
180
+ - `--cleanup-mermaid-assets`: remove generated Mermaid temp files (default)
213
181
 
214
- Run demo:
182
+ ## Test samples
215
183
 
216
- ```bash
217
- md2pdf ./tests/architecture-smoke-test.md
218
- ```
184
+ - Smoke test: `tests/architecture-smoke-test.md`
185
+ - Mermaid sample pack: `tests/samples/mermaid-all-diagram-types.md`
219
186
 
220
- Run the full Mermaid sample suite:
187
+ Run:
221
188
 
222
189
  ```bash
190
+ md2pdf ./tests/architecture-smoke-test.md
223
191
  md2pdf ./tests/samples/mermaid-all-diagram-types.md --keep-mermaid-assets
224
192
  ```
225
193
 
226
- ## Publish (maintainer)
227
-
228
- ```bash
229
- npm login
230
- npm pack --dry-run
231
- npm publish
232
- ```
194
+ ## Troubleshooting
233
195
 
234
- Package: `@dkothule/md2pdf`
196
+ - `mmdc not found`: install dependencies and verify `MERMAID_BIN`.
197
+ - Flowchart/graph labels missing in PDF: keep `MERMAID_AUTO_PDF_FALLBACK=true`.
198
+ - Diagram taking a full page: keep `MERMAID_PDF_FIT=true`.
199
+ - PDF engine missing: install `xelatex` or set `PDF_ENGINE`.
235
200
 
236
- ## Troubleshooting
201
+ ## Keywords
237
202
 
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`.
203
+ markdown to pdf, md to pdf, md2pdf, mermaid to pdf, mermaid svg, pandoc markdown pdf, markdown pdf cli, macOS markdown pdf, Linux markdown pdf
245
204
 
246
205
  ## License
247
206
 
@@ -3,8 +3,99 @@
3
3
  # Copyright (c) 2026 Deepak Kothule
4
4
  set -euo pipefail
5
5
 
6
+ YES=0
6
7
  OS="$(uname -s)"
7
8
 
9
+ usage() {
10
+ cat <<EOF
11
+ Usage: $(basename "$0") [options]
12
+
13
+ Install md2pdf runtime dependencies (system packages + pandocfilters).
14
+
15
+ Options:
16
+ -y, --yes Skip confirmation prompt and proceed immediately
17
+ -h, --help Show this help message
18
+
19
+ Supported platforms:
20
+ - macOS (Homebrew)
21
+ - Debian/Ubuntu Linux (apt)
22
+ EOF
23
+ }
24
+
25
+ parse_args() {
26
+ while [[ $# -gt 0 ]]; do
27
+ case "$1" in
28
+ -y|--yes)
29
+ YES=1
30
+ ;;
31
+ -h|--help)
32
+ usage
33
+ exit 0
34
+ ;;
35
+ *)
36
+ echo "Error: unknown option: $1" >&2
37
+ usage >&2
38
+ exit 1
39
+ ;;
40
+ esac
41
+ shift
42
+ done
43
+ }
44
+
45
+ confirm_install() {
46
+ if [[ "$YES" -eq 1 ]]; then
47
+ return
48
+ fi
49
+
50
+ if [[ ! -t 0 ]]; then
51
+ echo "Non-interactive shell detected. Re-run with --yes to proceed." >&2
52
+ exit 1
53
+ fi
54
+
55
+ echo "This command will install system packages for md2pdf and may prompt for sudo password."
56
+ echo "Detected OS: $OS"
57
+ printf "Continue? [y/N] "
58
+ local response
59
+ read -r response
60
+
61
+ case "${response,,}" in
62
+ y|yes)
63
+ ;;
64
+ *)
65
+ echo "Aborted."
66
+ exit 0
67
+ ;;
68
+ esac
69
+ }
70
+
71
+ has_pandocfilters() {
72
+ python3 - <<'PY' >/dev/null 2>&1
73
+ import pandocfilters
74
+ PY
75
+ }
76
+
77
+ install_python_dependency() {
78
+ if has_pandocfilters; then
79
+ echo "Python dependency already installed: pandocfilters"
80
+ return
81
+ fi
82
+
83
+ echo "Installing Python dependency: pandocfilters"
84
+ if python3 -m pip install --user pandocfilters; then
85
+ return
86
+ fi
87
+
88
+ if python3 -m pip install pandocfilters --break-system-packages; then
89
+ return
90
+ fi
91
+
92
+ echo "Failed to install pandocfilters automatically." >&2
93
+ echo "Please install manually with one of:" >&2
94
+ echo " python3 -m pip install --user pandocfilters" >&2
95
+ echo " python3 -m pip install pandocfilters --break-system-packages" >&2
96
+ exit 1
97
+ }
98
+
8
99
  install_macos() {
9
100
  if ! command -v brew >/dev/null 2>&1; then
10
101
  echo "Homebrew is required on macOS. Install from https://brew.sh and retry."
@@ -12,7 +103,11 @@ install_macos() {
12
103
  fi
13
104
 
14
105
  brew update
15
- brew install pandoc librsvg node python
106
+ brew install pandoc librsvg python
107
+
108
+ if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
109
+ brew install node
110
+ fi
16
111
 
17
112
  if ! command -v xelatex >/dev/null 2>&1; then
18
113
  echo "Installing BasicTeX for xelatex..."
@@ -26,14 +121,20 @@ install_debian_ubuntu() {
26
121
  sudo apt-get install -y \
27
122
  pandoc \
28
123
  librsvg2-bin \
29
- nodejs \
30
- npm \
31
124
  python3 \
32
125
  python3-venv \
33
126
  python3-pip \
127
+ python3-pandocfilters \
34
128
  texlive-xetex
129
+
130
+ if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
131
+ sudo apt-get install -y nodejs npm
132
+ fi
35
133
  }
36
134
 
135
+ parse_args "$@"
136
+ confirm_install
137
+
37
138
  if [[ "$OS" == "Darwin" ]]; then
38
139
  install_macos
39
140
  elif [[ "$OS" == "Linux" ]]; then
@@ -49,4 +150,6 @@ else
49
150
  exit 1
50
151
  fi
51
152
 
52
- echo "System dependencies installed."
153
+ install_python_dependency
154
+
155
+ echo "Runtime dependencies installed."
package/package.json CHANGED
@@ -1,9 +1,29 @@
1
1
  {
2
2
  "name": "@dkothule/md2pdf",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
  },
@@ -24,6 +44,7 @@
24
44
  ],
25
45
  "bin": {
26
46
  "md2pdf": "./bin/md2pdf",
47
+ "md2pdf-install-system-deps": "./install-system-deps.sh",
27
48
  "md2pdf-install-finder-action": "./scripts/install_md2pdf_quick_action.sh",
28
49
  "md2pdf-uninstall-finder-action": "./scripts/uninstall_md2pdf_quick_action.sh"
29
50
  },