markdown-pdf-export 2.0.1 → 2.1.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/README.md +27 -23
- package/cli.mjs +212 -20
- package/default.css +0 -4
- package/export.mjs +7 -0
- package/lib/doctor-report.mjs +56 -9
- package/lib/editor-setup.mjs +157 -10
- package/lib/page-breaks.mjs +51 -0
- package/lib/settings-schema.mjs +1 -1
- package/lib/studio-server.mjs +26 -7
- package/lib/term-style.mjs +27 -0
- package/lib/types.mjs +1 -1
- package/package.json +11 -6
- package/schema/settings.schema.json +1 -1
- package/studio/app.mjs +174 -18
- package/studio/style.css +63 -7
- package/templates/academic.json +1 -1
- package/templates/corporate.json +1 -1
- package/templates/minimal.json +1 -1
- package/templates/simple.json +1 -1
- package/templates/two-logo.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/markdown-pdf-export)
|
|
4
4
|
[](https://www.npmjs.com/package/markdown-pdf-export)
|
|
5
|
-
[](https://github.com/matinfo/markdown-pdf-export/actions/workflows/ci.yml)
|
|
6
|
-
[](https://github.com/matinfo/markdown-pdf-export/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/matinfo-tech/markdown-pdf-export/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/matinfo-tech/markdown-pdf-export/blob/main/LICENSE)
|
|
7
7
|
|
|
8
8
|
Turn Markdown files into clean PDFs from VS Code, Zed, Cursor, Claude or any AI assistant, or from
|
|
9
9
|
the command line.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
<p align="center">
|
|
12
|
+
<img src="https://raw.githubusercontent.com/matinfo-tech/markdown-pdf-export/main/docs/public/img/banner.jpeg" alt="Markdown PDF Export: Markdown to polished PDFs from VS Code, Copilot, Cursor, any MCP client or the command line" width="100%">
|
|
13
|
+
</p>
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Full documentation: <https://markdown-pdf.matinfo.tech/>
|
|
16
|
+
|
|
17
|
+

|
|
14
18
|
|
|
15
19
|
## Get started
|
|
16
20
|
|
|
@@ -32,9 +36,9 @@ real PDF update as you go. Click **Save**, then **Add to my editor**, and you ar
|
|
|
32
36
|
There is nothing to install first: `npx` downloads the package on first use and reuses it after.
|
|
33
37
|
Prefer the terminal? Run `npx -y markdown-pdf-export` with no arguments for a small menu.
|
|
34
38
|
|
|
35
|
-
More: [Get started](https://
|
|
36
|
-
[Studio](https://
|
|
37
|
-
[Design online, no install](https://
|
|
39
|
+
More: [Get started](https://markdown-pdf.matinfo.tech/start) ·
|
|
40
|
+
[Studio](https://markdown-pdf.matinfo.tech/studio) ·
|
|
41
|
+
[Design online, no install](https://markdown-pdf.matinfo.tech/online)
|
|
38
42
|
|
|
39
43
|
## Export a file
|
|
40
44
|
|
|
@@ -46,7 +50,7 @@ More: [Get started](https://matinfo.github.io/markdown-pdf-export/start) ·
|
|
|
46
50
|
|
|
47
51
|
The PDF is saved next to the Markdown file. To add the task or the assistant tool by hand, run
|
|
48
52
|
`npx -y markdown-pdf-export setup`, or see
|
|
49
|
-
[Editors](https://
|
|
53
|
+
[Editors](https://markdown-pdf.matinfo.tech/editors).
|
|
50
54
|
|
|
51
55
|
## What you get
|
|
52
56
|
|
|
@@ -60,18 +64,18 @@ The PDF is saved next to the Markdown file. To add the task or the assistant too
|
|
|
60
64
|
|
|
61
65
|
## Go further
|
|
62
66
|
|
|
63
|
-
- [Advanced topics](https://
|
|
64
|
-
- [Settings file](https://
|
|
65
|
-
- [Per-document settings](https://
|
|
66
|
-
- [Header and footer](https://
|
|
67
|
-
- [Styling](https://
|
|
68
|
-
- [Content](https://
|
|
69
|
-
- [Command line](https://
|
|
70
|
-
- [Assistant tools](https://
|
|
71
|
-
- [Browser](https://
|
|
72
|
-
- [Recipes](https://
|
|
73
|
-
- [Settings reference](https://
|
|
74
|
-
- [Placeholders reference](https://
|
|
67
|
+
- [Advanced topics](https://markdown-pdf.matinfo.tech/advanced/): a one-page map of everything below.
|
|
68
|
+
- [Settings file](https://markdown-pdf.matinfo.tech/advanced/settings-file): where it lives and how files are combined.
|
|
69
|
+
- [Per-document settings](https://markdown-pdf.matinfo.tech/advanced/per-document): change one document with front matter.
|
|
70
|
+
- [Header and footer](https://markdown-pdf.matinfo.tech/advanced/header-footer): zones, logos, page numbers and dates.
|
|
71
|
+
- [Styling](https://markdown-pdf.matinfo.tech/advanced/styling): your own CSS, fonts and code colours.
|
|
72
|
+
- [Content](https://markdown-pdf.matinfo.tech/advanced/content): maths, contents list, images and page breaks.
|
|
73
|
+
- [Command line](https://markdown-pdf.matinfo.tech/advanced/cli): every command and option.
|
|
74
|
+
- [Assistant tools](https://markdown-pdf.matinfo.tech/advanced/assistant-tools): the MCP server and its two tools.
|
|
75
|
+
- [Browser](https://markdown-pdf.matinfo.tech/advanced/browser): which browser is used and how to pick another.
|
|
76
|
+
- [Recipes](https://markdown-pdf.matinfo.tech/advanced/recipes): ready-made setups for common jobs.
|
|
77
|
+
- [Settings reference](https://markdown-pdf.matinfo.tech/reference/settings): every setting.
|
|
78
|
+
- [Placeholders reference](https://markdown-pdf.matinfo.tech/reference/placeholders): `{page}`, `{title}`, `{date}` and more.
|
|
75
79
|
|
|
76
80
|
## Help
|
|
77
81
|
|
|
@@ -82,12 +86,12 @@ npx -y markdown-pdf-export doctor
|
|
|
82
86
|
```
|
|
83
87
|
|
|
84
88
|
You can also ask the assistant: "Run doctor_markdown_pdf". For common problems, see
|
|
85
|
-
[Help](https://
|
|
89
|
+
[Help](https://markdown-pdf.matinfo.tech/help).
|
|
86
90
|
|
|
87
91
|
## Contributing
|
|
88
92
|
|
|
89
|
-
See [CONTRIBUTING.md](https://github.com/matinfo/markdown-pdf-export/blob/main/CONTRIBUTING.md) for development setup, tests and how the project is built.
|
|
93
|
+
See [CONTRIBUTING.md](https://github.com/matinfo-tech/markdown-pdf-export/blob/main/CONTRIBUTING.md) for development setup, tests and how the project is built.
|
|
90
94
|
|
|
91
95
|
## Licence
|
|
92
96
|
|
|
93
|
-
MIT. See [LICENSE](https://github.com/matinfo/markdown-pdf-export/blob/main/LICENSE).
|
|
97
|
+
MIT. See [LICENSE](https://github.com/matinfo-tech/markdown-pdf-export/blob/main/LICENSE).
|
package/cli.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* markdown-pdf-export studio design pages in the browser (live preview)
|
|
7
7
|
* markdown-pdf-export doctor [file.md] check browser + settings
|
|
8
8
|
* markdown-pdf-export init [--template t] create the settings file
|
|
9
|
+
* markdown-pdf-export init --from file install a settings file (e.g. from the online designer)
|
|
9
10
|
* markdown-pdf-export setup [editor] print editor task + MCP snippets
|
|
10
11
|
* markdown-pdf-export install-browser download Playwright's Chromium (~200 MB)
|
|
11
12
|
* markdown-pdf-export mcp run as an MCP server on stdio
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
*/
|
|
19
20
|
import { spawn } from "node:child_process";
|
|
20
21
|
import fs from "node:fs";
|
|
22
|
+
import os from "node:os";
|
|
21
23
|
import path from "node:path";
|
|
22
24
|
import process from "node:process";
|
|
23
25
|
import readline from "node:readline/promises";
|
|
@@ -38,8 +40,17 @@ import {
|
|
|
38
40
|
userSettingsPath,
|
|
39
41
|
} from "./lib/settings-loader.mjs";
|
|
40
42
|
import { formatDoctor } from "./lib/doctor-report.mjs";
|
|
43
|
+
import { makeStyle } from "./lib/term-style.mjs";
|
|
41
44
|
import { LOOKS, FONTS, applyPresets } from "./lib/looks.mjs";
|
|
42
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
EDITOR_IDS,
|
|
47
|
+
ITEM_LABELS,
|
|
48
|
+
applySetupItem,
|
|
49
|
+
buildEditorSetup,
|
|
50
|
+
editorStatus,
|
|
51
|
+
launchSpec,
|
|
52
|
+
pendingItems,
|
|
53
|
+
} from "./lib/editor-setup.mjs";
|
|
43
54
|
|
|
44
55
|
const BIN = "markdown-pdf-export";
|
|
45
56
|
const CLI_PATH = fileURLToPath(import.meta.url);
|
|
@@ -79,6 +90,7 @@ Usage:
|
|
|
79
90
|
${BIN} studio [--project] [--file <doc.md>] design pages in the browser
|
|
80
91
|
${BIN} doctor [file.md] [--json]
|
|
81
92
|
${BIN} init [--look <n>] [--font <n>] [--template <n>] [--project] [--force] [--list]
|
|
93
|
+
${BIN} init --from <file> [--project] [--force]
|
|
82
94
|
${BIN} setup [${EDITOR_IDS.join("|")}|all] [--write]
|
|
83
95
|
${BIN} install-browser
|
|
84
96
|
${BIN} mcp
|
|
@@ -272,12 +284,15 @@ async function main(argv) {
|
|
|
272
284
|
if (fromArg) setSettings(fromArg.data, fromArg.file);
|
|
273
285
|
|
|
274
286
|
if (isDoctor) {
|
|
275
|
-
const report =
|
|
287
|
+
const report = {
|
|
288
|
+
...(await doctorMarkdownPdf({ input_path: positional[0] })),
|
|
289
|
+
editors: editorStatus(),
|
|
290
|
+
};
|
|
276
291
|
if (asJson) {
|
|
277
292
|
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
278
293
|
return report.browser.available ? 0 : 1;
|
|
279
294
|
}
|
|
280
|
-
const { text, ok } = formatDoctor(report, { bin: BIN });
|
|
295
|
+
const { text, ok } = formatDoctor(report, { bin: BIN, style: makeStyle() });
|
|
281
296
|
process.stdout.write(text);
|
|
282
297
|
return ok ? 0 : 1;
|
|
283
298
|
}
|
|
@@ -319,7 +334,8 @@ async function runMenu() {
|
|
|
319
334
|
if (pick === "1") return runSetup([]);
|
|
320
335
|
if (pick === "2") return runStudio([]);
|
|
321
336
|
if (pick === "3") {
|
|
322
|
-
const
|
|
337
|
+
const report = { ...(await doctorMarkdownPdf({})), editors: editorStatus() };
|
|
338
|
+
const { text, ok } = formatDoctor(report, { bin: BIN, style: makeStyle() });
|
|
323
339
|
process.stdout.write(text);
|
|
324
340
|
return ok ? 0 : 1;
|
|
325
341
|
}
|
|
@@ -483,6 +499,77 @@ async function promptInit(templates) {
|
|
|
483
499
|
}
|
|
484
500
|
}
|
|
485
501
|
|
|
502
|
+
/** Image paths a settings object refers to in its header and footer, as written. */
|
|
503
|
+
function referencedImages(data) {
|
|
504
|
+
const found = [];
|
|
505
|
+
const walk = (node, key) => {
|
|
506
|
+
if (typeof node === "string") {
|
|
507
|
+
if (key === "src" || key?.endsWith("_image")) found.push(node);
|
|
508
|
+
} else if (Array.isArray(node)) {
|
|
509
|
+
for (const item of node) walk(item, key);
|
|
510
|
+
} else if (node && typeof node === "object") {
|
|
511
|
+
for (const [k, v] of Object.entries(node)) walk(v, k);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
walk(data.header);
|
|
515
|
+
walk(data.footer);
|
|
516
|
+
return [...new Set(found)];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** Where an image reference of a settings file at `dir` points on disk. */
|
|
520
|
+
function imageLocation(ref, data, dir) {
|
|
521
|
+
if (ref.startsWith("@/")) return path.resolve(dir, data.assets_directory ?? ".", ref.slice(2));
|
|
522
|
+
if (ref.startsWith("~/")) return path.join(os.homedir(), ref.slice(2));
|
|
523
|
+
return path.resolve(dir, ref);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** `init --from`: validate a settings file (for example the one downloaded from the online designer) and install it. */
|
|
527
|
+
function installSettingsFile(from, target, force) {
|
|
528
|
+
const source = path.resolve(from);
|
|
529
|
+
let text;
|
|
530
|
+
try {
|
|
531
|
+
text = fs.readFileSync(source, "utf8").replace(/^\uFEFF/, "");
|
|
532
|
+
} catch (error) {
|
|
533
|
+
throw new UsageError(`Cannot read ${source}: ${error.message}`);
|
|
534
|
+
}
|
|
535
|
+
let data;
|
|
536
|
+
try {
|
|
537
|
+
data = JSON.parse(text);
|
|
538
|
+
} catch (error) {
|
|
539
|
+
throw new UsageError(`${source} is not valid JSON: ${error.message}`);
|
|
540
|
+
}
|
|
541
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
542
|
+
throw new UsageError(`${source}: the top level must be a JSON object.`);
|
|
543
|
+
}
|
|
544
|
+
const { warnings } = applyPresets(data);
|
|
545
|
+
for (const warning of warnings) process.stderr.write(`${source}: ${warning}\n`);
|
|
546
|
+
|
|
547
|
+
const exists = fs.existsSync(target);
|
|
548
|
+
if (path.resolve(target) === source) {
|
|
549
|
+
process.stderr.write(`${BIN}: ${target} is already the settings file.\n`);
|
|
550
|
+
return 0;
|
|
551
|
+
}
|
|
552
|
+
if (exists && !force) {
|
|
553
|
+
process.stderr.write(`${BIN}: ${target} already exists — not overwriting (use --force).\n`);
|
|
554
|
+
return 1;
|
|
555
|
+
}
|
|
556
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
557
|
+
if (exists) {
|
|
558
|
+
fs.copyFileSync(target, `${target}.bak`);
|
|
559
|
+
process.stderr.write(`Kept the previous file as ${target}.bak\n`);
|
|
560
|
+
}
|
|
561
|
+
fs.writeFileSync(target, text.endsWith("\n") ? text : `${text}\n`);
|
|
562
|
+
process.stderr.write("Installed your settings to:\n");
|
|
563
|
+
process.stdout.write(`${target}\n`);
|
|
564
|
+
|
|
565
|
+
const dir = path.dirname(target);
|
|
566
|
+
for (const ref of referencedImages(data)) {
|
|
567
|
+
const where = imageLocation(ref, data, dir);
|
|
568
|
+
if (!fs.existsSync(where)) process.stderr.write(`Put your logo at ${where} (settings say "${ref}")\n`);
|
|
569
|
+
}
|
|
570
|
+
return 0;
|
|
571
|
+
}
|
|
572
|
+
|
|
486
573
|
async function runInit(argv) {
|
|
487
574
|
const flags = parseSubArgs(argv, {
|
|
488
575
|
template: "string",
|
|
@@ -491,12 +578,16 @@ async function runInit(argv) {
|
|
|
491
578
|
project: "boolean",
|
|
492
579
|
force: "boolean",
|
|
493
580
|
list: "boolean",
|
|
581
|
+
from: "string",
|
|
494
582
|
});
|
|
495
583
|
if (flags.help) {
|
|
496
584
|
process.stdout.write(
|
|
497
|
-
`Usage: ${BIN} init [--look <n>] [--font <n>] [--template <n>] [--project] [--force] [--list]\n
|
|
585
|
+
`Usage: ${BIN} init [--look <n>] [--font <n>] [--template <n>] [--project] [--force] [--list]\n` +
|
|
586
|
+
` ${BIN} init --from <file> [--project] [--force]\n\n` +
|
|
498
587
|
`Creates ${userSettingsPath()}\n` +
|
|
499
|
-
`(or ./${PROJECT_SETTINGS_FILENAME} with --project) from a template.\n
|
|
588
|
+
`(or ./${PROJECT_SETTINGS_FILENAME} with --project) from a template.\n` +
|
|
589
|
+
"--from installs a settings file you already have, such as the one downloaded from\n" +
|
|
590
|
+
"the online designer. It is checked first; an existing file is kept as .bak with --force.\n",
|
|
500
591
|
);
|
|
501
592
|
return 0;
|
|
502
593
|
}
|
|
@@ -510,6 +601,12 @@ async function runInit(argv) {
|
|
|
510
601
|
const target = flags.project
|
|
511
602
|
? path.resolve(PROJECT_SETTINGS_FILENAME)
|
|
512
603
|
: userSettingsPath();
|
|
604
|
+
if (flags.from !== undefined) {
|
|
605
|
+
if (flags.template || flags.look || flags.font) {
|
|
606
|
+
throw new UsageError("--from cannot be combined with --template, --look or --font.");
|
|
607
|
+
}
|
|
608
|
+
return installSettingsFile(flags.from, target, flags.force);
|
|
609
|
+
}
|
|
513
610
|
if (fs.existsSync(target) && !flags.force) {
|
|
514
611
|
process.stderr.write(
|
|
515
612
|
`${BIN}: ${target} already exists — not overwriting (use --force).\n`,
|
|
@@ -577,14 +674,90 @@ async function runInit(argv) {
|
|
|
577
674
|
|
|
578
675
|
// ── setup ────────────────────────────────────────────────────────────────────
|
|
579
676
|
|
|
677
|
+
/**
|
|
678
|
+
* Ask editor by editor; skip what is already set up. Returns an exit code
|
|
679
|
+
* (130 when the person aborts with Ctrl+C / Ctrl+D).
|
|
680
|
+
*/
|
|
681
|
+
async function setupInteractive(setups, c) {
|
|
682
|
+
const out = process.stdout;
|
|
683
|
+
const status = Object.fromEntries(editorStatus().map((e) => [e.id, e]));
|
|
684
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
685
|
+
let aborted = false;
|
|
686
|
+
rl.on("SIGINT", () => {
|
|
687
|
+
aborted = true;
|
|
688
|
+
rl.close();
|
|
689
|
+
});
|
|
690
|
+
const ask = async (question) => {
|
|
691
|
+
try {
|
|
692
|
+
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
693
|
+
return answer === "" || answer === "y" || answer === "yes" || answer === "o" || answer === "oui";
|
|
694
|
+
} catch {
|
|
695
|
+
aborted = true; // input closed
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
out.write(`\n${c.bold(`Set up ${BIN} ${SERVER_VERSION}`)}\n`);
|
|
701
|
+
out.write(c.dim(`Found: ${setups.map((s) => s.name).join(", ")}`) + "\n\n");
|
|
702
|
+
try {
|
|
703
|
+
for (const setup of setups) {
|
|
704
|
+
const todo = pendingItems(setup, status[setup.id]);
|
|
705
|
+
if (todo.length === 0) {
|
|
706
|
+
out.write(`${c.green("✓")} ${c.bold(setup.name)}: already set up\n`);
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
const what = todo.map((i) => ITEM_LABELS[i.kind]).join(" + ");
|
|
710
|
+
const yes = await ask(`${c.cyan("?")} Set up ${c.bold(setup.name)} (${what})? ${c.dim("[Y/n]")} `);
|
|
711
|
+
if (aborted) {
|
|
712
|
+
out.write(`\n${c.yellow("Setup stopped.")}\n`);
|
|
713
|
+
return 130;
|
|
714
|
+
}
|
|
715
|
+
if (!yes) {
|
|
716
|
+
out.write(` ${c.dim("· skipped")}\n`);
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
for (const item of todo) {
|
|
720
|
+
const label = ITEM_LABELS[item.kind];
|
|
721
|
+
if (item.write === "print") {
|
|
722
|
+
out.write(
|
|
723
|
+
` ${c.yellow("→")} ${label}: add this to ${item.file}` +
|
|
724
|
+
`${fs.existsSync(item.file) ? " (merge with what is there)" : ""}:\n` +
|
|
725
|
+
`${item.snippet.replace(/^/gm, " ")}\n`,
|
|
726
|
+
);
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
const { done, message } = applySetupItem(item, { stdio: "pipe" });
|
|
730
|
+
if (done) {
|
|
731
|
+
out.write(` ${c.green("✓")} ${label}: ${c.green(message)}\n`);
|
|
732
|
+
} else {
|
|
733
|
+
out.write(
|
|
734
|
+
` ${c.red("✗")} ${label}: ${message}\n` +
|
|
735
|
+
`${item.snippet.replace(/^/gm, " ")}\n`,
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
} finally {
|
|
741
|
+
rl.close();
|
|
742
|
+
}
|
|
743
|
+
const others = EDITOR_IDS.filter((id) => !setups.some((s) => s.id === id));
|
|
744
|
+
if (others.length) {
|
|
745
|
+
out.write(c.dim(`\nOther editors: ${BIN} setup <${others.join("|")}>`) + "\n");
|
|
746
|
+
}
|
|
747
|
+
return 0;
|
|
748
|
+
}
|
|
749
|
+
|
|
580
750
|
async function runSetup(argv) {
|
|
581
|
-
const flags = parseSubArgs(argv, { write: "boolean" });
|
|
751
|
+
const flags = parseSubArgs(argv, { write: "boolean", print: "boolean" });
|
|
582
752
|
if (flags.help) {
|
|
583
753
|
process.stdout.write(
|
|
584
|
-
`Usage: ${BIN} setup [${EDITOR_IDS.join("|")}|all] [--write]\n\n` +
|
|
585
|
-
"
|
|
586
|
-
"
|
|
587
|
-
"
|
|
754
|
+
`Usage: ${BIN} setup [${EDITOR_IDS.join("|")}|all] [--write|--print]\n\n` +
|
|
755
|
+
"Sets up the export task and AI tools in your editors (the ones found by default).\n" +
|
|
756
|
+
"In a terminal it asks editor by editor and skips what is already set up.\n" +
|
|
757
|
+
"--write set up everything without asking (scripts)\n" +
|
|
758
|
+
"--print only show what to add\n" +
|
|
759
|
+
"Files that do not exist yet are created and editor CLIs are run;\n" +
|
|
760
|
+
"existing files are never modified: you get the snippet to paste.\n",
|
|
588
761
|
);
|
|
589
762
|
return 0;
|
|
590
763
|
}
|
|
@@ -604,28 +777,47 @@ async function runSetup(argv) {
|
|
|
604
777
|
}
|
|
605
778
|
|
|
606
779
|
const out = process.stdout;
|
|
607
|
-
|
|
608
|
-
|
|
780
|
+
const c = makeStyle();
|
|
781
|
+
const interactive =
|
|
782
|
+
!flags.write && !flags.print && process.stdin.isTTY && process.stdout.isTTY;
|
|
783
|
+
if (interactive) {
|
|
784
|
+
const code = await setupInteractive(setups, c);
|
|
785
|
+
if (code !== 0) return code;
|
|
786
|
+
}
|
|
787
|
+
const status = flags.write ? Object.fromEntries(editorStatus().map((e) => [e.id, e])) : {};
|
|
788
|
+
for (const setup of interactive ? [] : setups) {
|
|
789
|
+
const todo = flags.write ? new Set(pendingItems(setup, status[setup.id])) : null;
|
|
790
|
+
out.write(
|
|
791
|
+
`\n${c.bold(`━━ ${setup.name} ━━`)}${setup.detected ? "" : c.dim(" (not detected)")}\n`,
|
|
792
|
+
);
|
|
609
793
|
for (const item of setup.items) {
|
|
610
|
-
out.write(`\n
|
|
611
|
-
if (item.file) out.write(` file: ${item.file}\n
|
|
794
|
+
out.write(`\n${c.cyan(`▸ ${item.label}`)}\n`);
|
|
795
|
+
if (item.file) out.write(c.dim(` file: ${item.file}`) + "\n");
|
|
612
796
|
out.write(`${item.snippet}\n`);
|
|
613
797
|
if (!flags.write) continue;
|
|
798
|
+
if (!todo.has(item)) {
|
|
799
|
+
const set = status[setup.id]?.[item.kind] === true;
|
|
800
|
+
out.write(` ${set ? c.green("✓") : c.dim("·")} ${set ? "already set up" : "not needed here"}\n`);
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
614
803
|
|
|
615
804
|
const { done, message } = applySetupItem(item);
|
|
616
|
-
|
|
805
|
+
const mark = done ? c.green("✓") : item.write === "print" ? c.yellow("→") : c.red("✗");
|
|
806
|
+
out.write(` ${mark} ${done ? c.green(message) : message}\n`);
|
|
617
807
|
}
|
|
618
808
|
}
|
|
619
809
|
|
|
810
|
+
const settingsFile = userSettingsPath();
|
|
620
811
|
out.write(
|
|
621
|
-
|
|
622
|
-
|
|
812
|
+
fs.existsSync(settingsFile)
|
|
813
|
+
? `\n${c.green("✓")} Settings file: ${settingsFile}\n`
|
|
814
|
+
: `\n${c.yellow("·")} No settings file yet (built-in look is used). Design your pages: ${c.cyan(`${BIN} studio`)}\n`,
|
|
623
815
|
);
|
|
624
816
|
const report = await doctorMarkdownPdf({});
|
|
625
817
|
out.write(
|
|
626
818
|
report.browser.available
|
|
627
|
-
?
|
|
628
|
-
:
|
|
819
|
+
? `${c.green("✓")} Browser: ${report.browser.version}\n`
|
|
820
|
+
: `${c.red("✗")} Browser: not found — ${report.browser.hint}\n`,
|
|
629
821
|
);
|
|
630
822
|
return report.browser.available ? 0 : 1;
|
|
631
823
|
}
|
package/default.css
CHANGED
package/export.mjs
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
userSettingsPath,
|
|
30
30
|
} from "./lib/settings-loader.mjs";
|
|
31
31
|
import { applyPresets } from "./lib/looks.mjs";
|
|
32
|
+
import { PAGE_BREAK_CSS, pageBreakComments } from "./lib/page-breaks.mjs";
|
|
32
33
|
import {
|
|
33
34
|
createPlaceholderResolver,
|
|
34
35
|
createRenderContext,
|
|
@@ -690,6 +691,8 @@ async function createMarkdown(options) {
|
|
|
690
691
|
highlight: highlightFn,
|
|
691
692
|
});
|
|
692
693
|
|
|
694
|
+
md.use(pageBreakComments);
|
|
695
|
+
|
|
693
696
|
if (options.emoji) {
|
|
694
697
|
try {
|
|
695
698
|
const emoji = await getEmojiPlugin();
|
|
@@ -871,6 +874,7 @@ export async function doctorMarkdownPdf(args) {
|
|
|
871
874
|
);
|
|
872
875
|
|
|
873
876
|
return {
|
|
877
|
+
version: SERVER_VERSION,
|
|
874
878
|
browser: browserInfo,
|
|
875
879
|
settings_sources: doc.sources,
|
|
876
880
|
settings: {
|
|
@@ -1274,6 +1278,9 @@ async function renderMarkdownToHtmlWithBody(inputPath, body, title, options) {
|
|
|
1274
1278
|
}
|
|
1275
1279
|
}
|
|
1276
1280
|
|
|
1281
|
+
// Page break markers work with or without the default stylesheet.
|
|
1282
|
+
styleBlocks += `<style>${PAGE_BREAK_CSS}</style>\n `;
|
|
1283
|
+
|
|
1277
1284
|
// Custom stylesheet
|
|
1278
1285
|
const stylesheetPath = resolveStylesheetPath(
|
|
1279
1286
|
path.dirname(inputPath),
|
package/lib/doctor-report.mjs
CHANGED
|
@@ -3,25 +3,35 @@
|
|
|
3
3
|
* where every problem comes with the one command that fixes it.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { plain } from "./term-style.mjs";
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* @param {object} report result of doctorMarkdownPdf()
|
|
8
|
-
* @param {{bin?: string, nodeVersion?: string}} [opts]
|
|
10
|
+
* @param {{bin?: string, nodeVersion?: string, style?: typeof plain}} [opts]
|
|
9
11
|
* @returns {{text: string, ok: boolean}}
|
|
10
12
|
*/
|
|
11
|
-
export function formatDoctor(
|
|
13
|
+
export function formatDoctor(
|
|
14
|
+
report,
|
|
15
|
+
{ bin = "markdown-pdf-export", nodeVersion = process.versions.node, style = plain } = {},
|
|
16
|
+
) {
|
|
17
|
+
const c = style;
|
|
12
18
|
const lines = [];
|
|
13
19
|
let ok = true;
|
|
14
|
-
const good = (msg) => lines.push(` ✓ ${msg}`);
|
|
20
|
+
const good = (msg) => lines.push(` ${c.green("✓")} ${msg}`);
|
|
15
21
|
const bad = (msg, fix) => {
|
|
16
22
|
ok = false;
|
|
17
|
-
lines.push(` ✗ ${msg}`);
|
|
18
|
-
if (fix) lines.push(` fix: ${fix}`);
|
|
23
|
+
lines.push(` ${c.red("✗")} ${msg}`);
|
|
24
|
+
if (fix) lines.push(` fix: ${c.cyan(fix)}`);
|
|
19
25
|
};
|
|
20
26
|
const info = (msg, hint) => {
|
|
21
|
-
lines.push(` · ${msg}`);
|
|
22
|
-
if (hint) lines.push(` ${hint}`);
|
|
27
|
+
lines.push(` ${c.dim("·")} ${msg}`);
|
|
28
|
+
if (hint) lines.push(` ${c.cyan(hint)}`);
|
|
23
29
|
};
|
|
24
30
|
|
|
31
|
+
if (report.version) {
|
|
32
|
+
good(`${c.bold(`${bin} ${report.version}`)}` + (report.server_dir ? c.dim(` (${report.server_dir})`) : ""));
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
const major = Number.parseInt(nodeVersion, 10);
|
|
26
36
|
if (major >= 20) good(`Node ${nodeVersion}`);
|
|
27
37
|
else bad(`Node ${nodeVersion} is too old (needs 20 or newer)`, "install Node 20+ from nodejs.org");
|
|
@@ -47,6 +57,43 @@ export function formatDoctor(report, { bin = "markdown-pdf-export", nodeVersion
|
|
|
47
57
|
(st.font_family ? " · custom font" : ""),
|
|
48
58
|
);
|
|
49
59
|
|
|
50
|
-
const head = ok
|
|
51
|
-
|
|
60
|
+
const head = ok
|
|
61
|
+
? c.green(c.bold("✨ Everything is ready."))
|
|
62
|
+
: c.red(c.bold("Something needs attention:"));
|
|
63
|
+
const editors = report.editors ? `\n${formatEditors(report.editors, bin, c)}` : "";
|
|
64
|
+
return { text: `${head}\n\n${lines.join("\n")}\n${editors}`, ok };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const PARTS = { task: "export task", mcp: "AI tools" };
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Editors section: what is set up where. Never fails the check — a missing
|
|
71
|
+
* editor is a choice, not an error.
|
|
72
|
+
* @param {ReturnType<typeof import("./editor-setup.mjs").editorStatus>} editors
|
|
73
|
+
* @param {string} bin
|
|
74
|
+
*/
|
|
75
|
+
export function formatEditors(editors, bin = "markdown-pdf-export", style = plain) {
|
|
76
|
+
const c = style;
|
|
77
|
+
const lines = [c.bold("Editors:")];
|
|
78
|
+
for (const e of editors.filter((x) => x.detected)) {
|
|
79
|
+
const parts = Object.keys(PARTS).filter((k) => e[k] !== undefined);
|
|
80
|
+
const done = parts.filter((k) => e[k] === true);
|
|
81
|
+
const missing = parts.filter((k) => e[k] !== true);
|
|
82
|
+
const label = (ks) => ks.map((k) => PARTS[k]).join(", ");
|
|
83
|
+
if (missing.length === 0) {
|
|
84
|
+
lines.push(` ${c.green("✓")} ${c.bold(e.name)}: ${label(done)}`);
|
|
85
|
+
} else {
|
|
86
|
+
const note = e.mcp === "project" ? " (only in some project folders)" : "";
|
|
87
|
+
lines.push(
|
|
88
|
+
` ${c.yellow("·")} ${c.bold(e.name)}: ${done.length ? `${label(done)} ${c.green("✓")}, ` : ""}` +
|
|
89
|
+
c.yellow(`${label(missing)} not set up${note}`),
|
|
90
|
+
` add: ${c.cyan(`${bin} setup ${e.id} --write`)}`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
for (const w of e.warnings ?? []) lines.push(` ${c.yellow("!")} ${c.yellow(w)}`);
|
|
94
|
+
}
|
|
95
|
+
const absent = editors.filter((x) => !x.detected).map((x) => x.name);
|
|
96
|
+
// Not installed is a choice, not a problem: neutral grey, never red.
|
|
97
|
+
if (absent.length) lines.push(c.dim(` · Not found: ${absent.join(", ")}`));
|
|
98
|
+
return `${lines.join("\n")}\n`;
|
|
52
99
|
}
|