@helping-ai-workflow/md2doc 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/bin/md2html.js +32 -10
- package/bin/md2pdf.js +29 -9
- package/package.json +2 -2
package/bin/md2html.js
CHANGED
|
@@ -14,7 +14,7 @@ function printHelp() {
|
|
|
14
14
|
`md2${FORMAT} — render Markdown to ${FORMAT.toUpperCase()} (WaveDrom / Mermaid / Graphviz supported)`,
|
|
15
15
|
'',
|
|
16
16
|
'Usage:',
|
|
17
|
-
` md2${FORMAT} <input.md> [<input2.md> ...] # render each to <stem
|
|
17
|
+
` md2${FORMAT} <input.md> [<input2.md> ...] # render each to <stem>_gen.${FORMAT} next to source`,
|
|
18
18
|
` md2${FORMAT} <input.md> --out <path.${FORMAT}> # explicit output (single-file mode)`,
|
|
19
19
|
` md2${FORMAT} <input.md> --open # render then open viewer`,
|
|
20
20
|
` md2${FORMAT} <input.md> --quiet # suppress progress output`,
|
|
@@ -79,12 +79,23 @@ function parseArgs(argv) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function deriveOutput(input, format) {
|
|
82
|
+
// Default suffix matches the workspace Makefile convention: <stem>_gen.<format>.
|
|
82
83
|
const stem = input.replace(/\.md$/i, '');
|
|
83
84
|
if (stem === input) {
|
|
84
|
-
// No .md extension — append .<format>.
|
|
85
|
-
return input + '.' + format;
|
|
85
|
+
// No .md extension — append _gen.<format>.
|
|
86
|
+
return input + '_gen.' + format;
|
|
87
|
+
}
|
|
88
|
+
return stem + '_gen.' + format;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function isWSL() {
|
|
92
|
+
if (process.platform !== 'linux') return false;
|
|
93
|
+
if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) return true;
|
|
94
|
+
try {
|
|
95
|
+
return fs.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop');
|
|
96
|
+
} catch (_) {
|
|
97
|
+
return false;
|
|
86
98
|
}
|
|
87
|
-
return stem + '.' + format;
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
function openViewer(filePath) {
|
|
@@ -94,12 +105,23 @@ function openViewer(filePath) {
|
|
|
94
105
|
cmd = 'open'; args = [filePath];
|
|
95
106
|
} else if (platform === 'win32') {
|
|
96
107
|
cmd = 'cmd'; args = ['/c', 'start', '""', filePath];
|
|
108
|
+
} else if (isWSL()) {
|
|
109
|
+
// Convert the WSL Linux path to a Windows-side path then launch via explorer.exe,
|
|
110
|
+
// which uses Windows file associations (.html → default browser, .pdf → default reader).
|
|
111
|
+
const r = spawnSync('wslpath', ['-w', filePath], { encoding: 'utf8' });
|
|
112
|
+
if (r.status === 0 && r.stdout) {
|
|
113
|
+
cmd = 'explorer.exe'; args = [r.stdout.trim()];
|
|
114
|
+
} else {
|
|
115
|
+
cmd = 'xdg-open'; args = [filePath];
|
|
116
|
+
}
|
|
97
117
|
} else {
|
|
98
118
|
cmd = 'xdg-open'; args = [filePath];
|
|
99
119
|
}
|
|
100
120
|
const r = spawnSync(cmd, args, { stdio: 'ignore' });
|
|
101
|
-
|
|
102
|
-
|
|
121
|
+
// explorer.exe returns exit code 1 on success (Windows quirk via WSL interop),
|
|
122
|
+
// so a non-zero exit is not necessarily a failure when launching via explorer.
|
|
123
|
+
if (r.error) {
|
|
124
|
+
process.stderr.write(`warning: could not launch viewer for ${filePath}: ${r.error.message}\n`);
|
|
103
125
|
}
|
|
104
126
|
}
|
|
105
127
|
|
|
@@ -113,10 +135,10 @@ function main() {
|
|
|
113
135
|
process.exit(1);
|
|
114
136
|
}
|
|
115
137
|
const output = (args.out !== null) ? args.out : deriveOutput(input, FORMAT);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const r = spawnSync(process.execPath, [LIB, input, output], { stdio
|
|
138
|
+
// lib/md2doc.js prints its own "[FORMAT] input → output" line; redirect its stdout
|
|
139
|
+
// when --quiet so neither layer emits progress.
|
|
140
|
+
const stdio = args.quiet ? ['inherit', 'ignore', 'inherit'] : 'inherit';
|
|
141
|
+
const r = spawnSync(process.execPath, [LIB, input, output], { stdio });
|
|
120
142
|
if (r.status !== 0) {
|
|
121
143
|
process.stderr.write(`error: render failed for ${input} (exit ${r.status})\n`);
|
|
122
144
|
process.exit(r.status || 1);
|
package/bin/md2pdf.js
CHANGED
|
@@ -14,7 +14,7 @@ function printHelp() {
|
|
|
14
14
|
`md2${FORMAT} — render Markdown to ${FORMAT.toUpperCase()} (WaveDrom / Mermaid / Graphviz supported)`,
|
|
15
15
|
'',
|
|
16
16
|
'Usage:',
|
|
17
|
-
` md2${FORMAT} <input.md> [<input2.md> ...] # render each to <stem
|
|
17
|
+
` md2${FORMAT} <input.md> [<input2.md> ...] # render each to <stem>_gen.${FORMAT} next to source`,
|
|
18
18
|
` md2${FORMAT} <input.md> --out <path.${FORMAT}> # explicit output (single-file mode)`,
|
|
19
19
|
` md2${FORMAT} <input.md> --open # render then open viewer`,
|
|
20
20
|
` md2${FORMAT} <input.md> --quiet # suppress progress output`,
|
|
@@ -79,11 +79,22 @@ function parseArgs(argv) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function deriveOutput(input, format) {
|
|
82
|
+
// Default suffix matches the workspace Makefile convention: <stem>_gen.<format>.
|
|
82
83
|
const stem = input.replace(/\.md$/i, '');
|
|
83
84
|
if (stem === input) {
|
|
84
|
-
return input + '.' + format;
|
|
85
|
+
return input + '_gen.' + format;
|
|
86
|
+
}
|
|
87
|
+
return stem + '_gen.' + format;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isWSL() {
|
|
91
|
+
if (process.platform !== 'linux') return false;
|
|
92
|
+
if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) return true;
|
|
93
|
+
try {
|
|
94
|
+
return fs.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop');
|
|
95
|
+
} catch (_) {
|
|
96
|
+
return false;
|
|
85
97
|
}
|
|
86
|
-
return stem + '.' + format;
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
function openViewer(filePath) {
|
|
@@ -93,12 +104,21 @@ function openViewer(filePath) {
|
|
|
93
104
|
cmd = 'open'; args = [filePath];
|
|
94
105
|
} else if (platform === 'win32') {
|
|
95
106
|
cmd = 'cmd'; args = ['/c', 'start', '""', filePath];
|
|
107
|
+
} else if (isWSL()) {
|
|
108
|
+
// Convert the WSL Linux path to a Windows-side path then launch via explorer.exe,
|
|
109
|
+
// which uses Windows file associations (.html → default browser, .pdf → default reader).
|
|
110
|
+
const r = spawnSync('wslpath', ['-w', filePath], { encoding: 'utf8' });
|
|
111
|
+
if (r.status === 0 && r.stdout) {
|
|
112
|
+
cmd = 'explorer.exe'; args = [r.stdout.trim()];
|
|
113
|
+
} else {
|
|
114
|
+
cmd = 'xdg-open'; args = [filePath];
|
|
115
|
+
}
|
|
96
116
|
} else {
|
|
97
117
|
cmd = 'xdg-open'; args = [filePath];
|
|
98
118
|
}
|
|
99
119
|
const r = spawnSync(cmd, args, { stdio: 'ignore' });
|
|
100
|
-
if (r.error
|
|
101
|
-
process.stderr.write(`warning: could not launch viewer for ${filePath}\n`);
|
|
120
|
+
if (r.error) {
|
|
121
|
+
process.stderr.write(`warning: could not launch viewer for ${filePath}: ${r.error.message}\n`);
|
|
102
122
|
}
|
|
103
123
|
}
|
|
104
124
|
|
|
@@ -112,10 +132,10 @@ function main() {
|
|
|
112
132
|
process.exit(1);
|
|
113
133
|
}
|
|
114
134
|
const output = (args.out !== null) ? args.out : deriveOutput(input, FORMAT);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const r = spawnSync(process.execPath, [LIB, input, output], { stdio
|
|
135
|
+
// lib/md2doc.js prints its own "[FORMAT] input → output" line; redirect its stdout
|
|
136
|
+
// when --quiet so neither layer emits progress.
|
|
137
|
+
const stdio = args.quiet ? ['inherit', 'ignore', 'inherit'] : 'inherit';
|
|
138
|
+
const r = spawnSync(process.execPath, [LIB, input, output], { stdio });
|
|
119
139
|
if (r.status !== 0) {
|
|
120
140
|
process.stderr.write(`error: render failed for ${input} (exit ${r.status})\n`);
|
|
121
141
|
process.exit(r.status || 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helping-ai-workflow/md2doc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Markdown → HTML / PDF renderer with WaveDrom, Mermaid, and Graphviz support",
|
|
5
5
|
"keywords": ["markdown", "html", "pdf", "renderer", "wavedrom", "mermaid", "graphviz"],
|
|
6
6
|
"main": "lib/md2doc.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"marked": "^14.1.0",
|
|
22
|
-
"puppeteer": "^
|
|
22
|
+
"puppeteer": "^24.15.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"test": "node test/md2doc.test.js"
|