@dkothule/md2pdf 1.0.4 → 1.0.6
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 +19 -8
- package/install-system-deps.sh +123 -12
- package/package.json +1 -1
- package/scripts/install_md2pdf_quick_action.sh +40 -1
package/README.md
CHANGED
|
@@ -54,18 +54,22 @@ npm i -g @dkothule/md2pdf
|
|
|
54
54
|
2) Install runtime dependencies (system packages + `pandocfilters`):
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
md2pdf-install-system-deps
|
|
57
|
+
md2pdf-install-system-deps --yes
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
If you prefer an interactive confirmation prompt, run:
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
md2pdf-install-system-deps
|
|
63
|
+
md2pdf-install-system-deps
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
3) Verify:
|
|
66
|
+
3) Verify runtime tools + CLI:
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
|
+
pandoc --version | head -n 1
|
|
70
|
+
xelatex --version | head -n 1
|
|
71
|
+
rsvg-convert --version
|
|
72
|
+
python3 -c "import pandocfilters; print('pandocfilters ok')"
|
|
69
73
|
md2pdf --version
|
|
70
74
|
md2pdf --help
|
|
71
75
|
```
|
|
@@ -105,16 +109,20 @@ Install Finder context menu action:
|
|
|
105
109
|
md2pdf-install-finder-action
|
|
106
110
|
```
|
|
107
111
|
|
|
108
|
-
|
|
112
|
+
If it does not appear in Finder right away:
|
|
113
|
+
|
|
114
|
+
1. Right-click a `.md` file and choose `Quick Actions` -> `Customize...`
|
|
115
|
+
2. Enable `Convert Markdown to PDF` under `Extensions` -> `Finder`
|
|
116
|
+
3. Restart Finder:
|
|
109
117
|
|
|
110
118
|
```bash
|
|
111
|
-
|
|
119
|
+
killall Finder
|
|
112
120
|
```
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
Uninstall Finder context menu action:
|
|
115
123
|
|
|
116
124
|
```bash
|
|
117
|
-
|
|
125
|
+
md2pdf-uninstall-finder-action
|
|
118
126
|
```
|
|
119
127
|
|
|
120
128
|
After installation, right-click any `.md` file in Finder:
|
|
@@ -218,6 +226,9 @@ md2pdf ./tests/samples/mermaid-all-diagram-types.md --keep-mermaid-assets
|
|
|
218
226
|
- Flowchart/graph labels missing in PDF: keep `MERMAID_AUTO_PDF_FALLBACK=true`.
|
|
219
227
|
- Diagram taking a full page: keep `MERMAID_PDF_FIT=true`.
|
|
220
228
|
- PDF engine missing: install `xelatex` or set `PDF_ENGINE`.
|
|
229
|
+
- On macOS, if `xelatex` is still missing after `md2pdf-install-system-deps`:
|
|
230
|
+
- Add TeX to PATH: `echo 'export PATH="/Library/TeX/texbin:$PATH"' >> ~/.zshrc && source ~/.zshrc`
|
|
231
|
+
- If binary is still missing: `sudo /Library/TeX/texbin/tlmgr install collection-xetex`
|
|
221
232
|
|
|
222
233
|
## Keywords
|
|
223
234
|
|
package/install-system-deps.sh
CHANGED
|
@@ -5,6 +5,7 @@ set -euo pipefail
|
|
|
5
5
|
|
|
6
6
|
YES=0
|
|
7
7
|
OS="$(uname -s)"
|
|
8
|
+
PYTHON_BIN=""
|
|
8
9
|
|
|
9
10
|
usage() {
|
|
10
11
|
cat <<EOF
|
|
@@ -71,30 +72,143 @@ confirm_install() {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
has_pandocfilters() {
|
|
74
|
-
|
|
75
|
+
local python_bin="$1"
|
|
76
|
+
"$python_bin" - <<'PY' >/dev/null 2>&1
|
|
75
77
|
import pandocfilters
|
|
76
78
|
PY
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
resolve_python_bin() {
|
|
82
|
+
local candidate
|
|
83
|
+
local -a candidates
|
|
84
|
+
|
|
85
|
+
candidates=("/opt/homebrew/bin/python3" "/usr/local/bin/python3")
|
|
86
|
+
if command -v python3 >/dev/null 2>&1; then
|
|
87
|
+
candidates+=("$(command -v python3)")
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
for candidate in "${candidates[@]}"; do
|
|
91
|
+
[[ -n "$candidate" ]] || continue
|
|
92
|
+
[[ -x "$candidate" ]] || continue
|
|
93
|
+
if "$candidate" -c 'import sys; print(sys.executable)' >/dev/null 2>&1; then
|
|
94
|
+
printf '%s' "$candidate"
|
|
95
|
+
return 0
|
|
96
|
+
fi
|
|
97
|
+
done
|
|
98
|
+
|
|
99
|
+
return 1
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
ensure_python_bin() {
|
|
103
|
+
if PYTHON_BIN="$(resolve_python_bin)"; then
|
|
104
|
+
echo "Using Python interpreter: $PYTHON_BIN"
|
|
105
|
+
return
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
echo "Error: python3 not found after dependency installation." >&2
|
|
109
|
+
if [[ "$OS" == "Darwin" ]]; then
|
|
110
|
+
echo "Install Python with Homebrew and retry:" >&2
|
|
111
|
+
echo " brew install python" >&2
|
|
112
|
+
elif [[ "$OS" == "Linux" ]]; then
|
|
113
|
+
echo "Install Python and pip, then retry:" >&2
|
|
114
|
+
echo " sudo apt-get install -y python3 python3-pip" >&2
|
|
115
|
+
fi
|
|
116
|
+
exit 1
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ensure_python_pip() {
|
|
120
|
+
local python_bin="$1"
|
|
121
|
+
if "$python_bin" -m pip --version >/dev/null 2>&1; then
|
|
122
|
+
return
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
"$python_bin" -m ensurepip --upgrade >/dev/null 2>&1 || true
|
|
126
|
+
"$python_bin" -m pip --version >/dev/null 2>&1
|
|
127
|
+
}
|
|
128
|
+
|
|
79
129
|
install_python_dependency() {
|
|
80
|
-
|
|
130
|
+
local python_bin="$1"
|
|
131
|
+
|
|
132
|
+
if ! ensure_python_pip "$python_bin"; then
|
|
133
|
+
echo "Error: pip is not available for $python_bin." >&2
|
|
134
|
+
echo "Install pip and retry. Example:" >&2
|
|
135
|
+
echo " $python_bin -m ensurepip --upgrade" >&2
|
|
136
|
+
exit 1
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
if has_pandocfilters "$python_bin"; then
|
|
81
140
|
echo "Python dependency already installed: pandocfilters"
|
|
82
141
|
return
|
|
83
142
|
fi
|
|
84
143
|
|
|
85
144
|
echo "Installing Python dependency: pandocfilters"
|
|
86
|
-
if
|
|
145
|
+
if "$python_bin" -m pip install --user pandocfilters; then
|
|
87
146
|
return
|
|
88
147
|
fi
|
|
89
148
|
|
|
90
|
-
if
|
|
149
|
+
if "$python_bin" -m pip install pandocfilters --break-system-packages; then
|
|
91
150
|
return
|
|
92
151
|
fi
|
|
93
152
|
|
|
94
153
|
echo "Failed to install pandocfilters automatically." >&2
|
|
95
154
|
echo "Please install manually with one of:" >&2
|
|
96
|
-
echo "
|
|
97
|
-
echo "
|
|
155
|
+
echo " $python_bin -m pip install --user pandocfilters" >&2
|
|
156
|
+
echo " $python_bin -m pip install pandocfilters --break-system-packages" >&2
|
|
157
|
+
exit 1
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
ensure_tex_path_macos() {
|
|
161
|
+
local tex_bin="/Library/TeX/texbin"
|
|
162
|
+
if [[ ! -d "$tex_bin" ]]; then
|
|
163
|
+
return
|
|
164
|
+
fi
|
|
165
|
+
|
|
166
|
+
case ":$PATH:" in
|
|
167
|
+
*":$tex_bin:"*)
|
|
168
|
+
;;
|
|
169
|
+
*)
|
|
170
|
+
export PATH="$tex_bin:$PATH"
|
|
171
|
+
;;
|
|
172
|
+
esac
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
ensure_xelatex_macos() {
|
|
176
|
+
ensure_tex_path_macos
|
|
177
|
+
if command -v xelatex >/dev/null 2>&1; then
|
|
178
|
+
return
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
echo "Installing BasicTeX for xelatex..."
|
|
182
|
+
brew install --cask basictex
|
|
183
|
+
ensure_tex_path_macos
|
|
184
|
+
|
|
185
|
+
if command -v xelatex >/dev/null 2>&1; then
|
|
186
|
+
return
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
local tlmgr_bin="/Library/TeX/texbin/tlmgr"
|
|
190
|
+
if [[ -x "$tlmgr_bin" ]]; then
|
|
191
|
+
if [[ -t 0 ]]; then
|
|
192
|
+
echo "BasicTeX installed but xelatex is still missing. Installing TeX collection-xetex..."
|
|
193
|
+
sudo "$tlmgr_bin" install collection-xetex || true
|
|
194
|
+
ensure_tex_path_macos
|
|
195
|
+
else
|
|
196
|
+
echo "BasicTeX installed but xelatex is still missing."
|
|
197
|
+
echo "Run this command to install it:"
|
|
198
|
+
echo " sudo $tlmgr_bin install collection-xetex"
|
|
199
|
+
fi
|
|
200
|
+
fi
|
|
201
|
+
|
|
202
|
+
if command -v xelatex >/dev/null 2>&1; then
|
|
203
|
+
return
|
|
204
|
+
fi
|
|
205
|
+
|
|
206
|
+
echo "Error: xelatex is still not available." >&2
|
|
207
|
+
echo "If /Library/TeX/texbin/xelatex exists, add TeX to PATH and restart your shell:" >&2
|
|
208
|
+
echo " echo 'export PATH=\"/Library/TeX/texbin:\$PATH\"' >> ~/.zshrc" >&2
|
|
209
|
+
echo " source ~/.zshrc" >&2
|
|
210
|
+
echo "If xelatex binary is missing, install it with:" >&2
|
|
211
|
+
echo " sudo /Library/TeX/texbin/tlmgr install collection-xetex" >&2
|
|
98
212
|
exit 1
|
|
99
213
|
}
|
|
100
214
|
|
|
@@ -111,11 +225,7 @@ install_macos() {
|
|
|
111
225
|
brew install node
|
|
112
226
|
fi
|
|
113
227
|
|
|
114
|
-
|
|
115
|
-
echo "Installing BasicTeX for xelatex..."
|
|
116
|
-
brew install --cask basictex
|
|
117
|
-
echo "BasicTeX installed. You may need to restart your shell before retrying."
|
|
118
|
-
fi
|
|
228
|
+
ensure_xelatex_macos
|
|
119
229
|
}
|
|
120
230
|
|
|
121
231
|
install_debian_ubuntu() {
|
|
@@ -152,6 +262,7 @@ else
|
|
|
152
262
|
exit 1
|
|
153
263
|
fi
|
|
154
264
|
|
|
155
|
-
|
|
265
|
+
ensure_python_bin
|
|
266
|
+
install_python_dependency "$PYTHON_BIN"
|
|
156
267
|
|
|
157
268
|
echo "Runtime dependencies installed."
|
package/package.json
CHANGED
|
@@ -117,6 +117,42 @@ if [[ ! -x "\$MD2PDF_SCRIPT" ]] && [[ -z "\$(command -v md2pdf 2>/dev
|
|
|
117
117
|
print -u2 -- "Error: md2pdf is not in PATH: \$PATH"
|
|
118
118
|
exit 127
|
|
119
119
|
fi
|
|
120
|
+
|
|
121
|
+
unset PYTHONNOUSERSITE
|
|
122
|
+
pick_python_with_pandocfilters() {
|
|
123
|
+
local candidate
|
|
124
|
+
local -a candidates
|
|
125
|
+
candidates=("/opt/homebrew/bin/python3" "/usr/local/bin/python3")
|
|
126
|
+
if [[ -n "\$(command -v python3 2>/dev/null)" ]]; then
|
|
127
|
+
candidates+=("\$(command -v python3)")
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
for candidate in "\${candidates[@]}"; do
|
|
131
|
+
[[ -n "\$candidate" ]] || continue
|
|
132
|
+
[[ -x "\$candidate" ]] || continue
|
|
133
|
+
if "\$candidate" - <<'PY' >/dev/null 2>&1
|
|
134
|
+
import pandocfilters
|
|
135
|
+
PY
|
|
136
|
+
then
|
|
137
|
+
print -r -- "\$candidate"
|
|
138
|
+
return 0
|
|
139
|
+
fi
|
|
140
|
+
done
|
|
141
|
+
return 1
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
PYTHON_BIN="\$(pick_python_with_pandocfilters || true)"
|
|
145
|
+
if [[ -z "\$PYTHON_BIN" ]]; then
|
|
146
|
+
print -u2 -- "Error: Missing Python dependency: pandocfilters."
|
|
147
|
+
print -u2 -- "Install with:"
|
|
148
|
+
if [[ -x /opt/homebrew/bin/python3 ]]; then
|
|
149
|
+
print -u2 -- " /opt/homebrew/bin/python3 -m pip install --user pandocfilters"
|
|
150
|
+
fi
|
|
151
|
+
print -u2 -- " python3 -m pip install --user pandocfilters"
|
|
152
|
+
exit 1
|
|
153
|
+
fi
|
|
154
|
+
export PYTHON="\$PYTHON_BIN"
|
|
155
|
+
|
|
120
156
|
for f in "\$@"; do
|
|
121
157
|
case "\$f" in
|
|
122
158
|
*.md|*.MD) ;;
|
|
@@ -255,5 +291,8 @@ echo "Installed Quick Action: $WORKFLOW_NAME"
|
|
|
255
291
|
echo "Location: $WORKFLOW_DIR"
|
|
256
292
|
echo "Using md2pdf executable: $MD2PDF_SCRIPT"
|
|
257
293
|
echo
|
|
258
|
-
echo "If it does not appear
|
|
294
|
+
echo "If it does not appear in Finder context menu:"
|
|
295
|
+
echo " 1) Right-click a .md file -> Quick Actions -> Customize..."
|
|
296
|
+
echo " 2) Enable '$WORKFLOW_NAME' in Extensions -> Finder"
|
|
297
|
+
echo " 3) Restart Finder"
|
|
259
298
|
echo " killall Finder"
|