@dkothule/md2pdf 1.0.5 → 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 +8 -4
- package/install-system-deps.sh +67 -7
- package/package.json +1 -1
- package/scripts/install_md2pdf_quick_action.sh +40 -1
package/README.md
CHANGED
|
@@ -109,16 +109,20 @@ Install Finder context menu action:
|
|
|
109
109
|
md2pdf-install-finder-action
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
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:
|
|
113
117
|
|
|
114
118
|
```bash
|
|
115
|
-
|
|
119
|
+
killall Finder
|
|
116
120
|
```
|
|
117
121
|
|
|
118
|
-
|
|
122
|
+
Uninstall Finder context menu action:
|
|
119
123
|
|
|
120
124
|
```bash
|
|
121
|
-
|
|
125
|
+
md2pdf-uninstall-finder-action
|
|
122
126
|
```
|
|
123
127
|
|
|
124
128
|
After installation, right-click any `.md` file in Finder:
|
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,88 @@ 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
|
|
98
157
|
exit 1
|
|
99
158
|
}
|
|
100
159
|
|
|
@@ -203,6 +262,7 @@ else
|
|
|
203
262
|
exit 1
|
|
204
263
|
fi
|
|
205
264
|
|
|
206
|
-
|
|
265
|
+
ensure_python_bin
|
|
266
|
+
install_python_dependency "$PYTHON_BIN"
|
|
207
267
|
|
|
208
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"
|