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.
@@ -15,7 +15,9 @@ export const SERVER_NAME = "markdown-pdf-export";
15
15
  /** Key of the MCP server entry and task label — match the docs. */
16
16
  export const MCP_KEY = "markdown-pdf";
17
17
  export const TASK_LABEL = "Markdown: Export to PDF";
18
- export const EDITOR_IDS = ["zed", "vscode", "cursor", "claude-code", "claude-desktop"];
18
+ export const EDITOR_IDS = ["zed", "vscode", "cursor", "claude-code", "claude-desktop", "copilot-cli"];
19
+ /** Short names people type for an editor id. */
20
+ export const EDITOR_ALIASES = { claude: "claude-code", code: "vscode", copilot: "copilot-cli" };
19
21
 
20
22
  /**
21
23
  * Version managers install node under a version-specific directory; editors
@@ -98,7 +100,8 @@ function roots({ home, platform, env }) {
98
100
  * @property {string|null} file target file (null for CLI-only)
99
101
  * @property {string} snippet text to show / write
100
102
  * @property {"create"|"print"|"command"} write safe-write strategy
101
- * @property {{cmd: string, args: string[]}} [run] CLI to run for "command"
103
+ * @property {{cmd: string, args: string[], fallbacks?: string[]}} [run]
104
+ * CLI to run for "command"; `fallbacks` are full paths tried when `cmd` is not on PATH
102
105
  */
103
106
 
104
107
  /**
@@ -108,6 +111,7 @@ function roots({ home, platform, env }) {
108
111
  * @returns {{id: string, name: string, detected: boolean, items: SetupItem[]}}
109
112
  */
110
113
  export function buildEditorSetup(editor, launch, ctx = {}) {
114
+ editor = EDITOR_ALIASES[editor] ?? editor;
111
115
  const home = ctx.home ?? os.homedir();
112
116
  const platform = ctx.platform ?? process.platform;
113
117
  const env = ctx.env ?? process.env;
@@ -128,7 +132,8 @@ export function buildEditorSetup(editor, launch, ctx = {}) {
128
132
  kind: "task",
129
133
  label: "Zed task (add to tasks.json)",
130
134
  file: path.join(dir, "tasks.json"),
131
- write: "print",
135
+ // Zed files are JSONC: create a missing one, never edit an existing one.
136
+ write: exists(path.join(dir, "tasks.json")) ? "print" : "create",
132
137
  snippet: json([
133
138
  {
134
139
  label: TASK_LABEL,
@@ -155,14 +160,15 @@ export function buildEditorSetup(editor, launch, ctx = {}) {
155
160
  const isCursor = editor === "cursor";
156
161
  const userDir = path.join(r.userData, isCursor ? "Cursor" : "Code", "User");
157
162
  const mcpFile = path.join(home, ".cursor", "mcp.json");
163
+ const taskFile = path.join(userDir, "tasks.json");
158
164
  const addMcp = JSON.stringify({ name: MCP_KEY, ...server });
159
165
  /** @type {SetupItem[]} */
160
166
  const items = [
161
167
  {
162
168
  kind: "task",
163
169
  label: `${isCursor ? "Cursor" : "VS Code"} task (add to tasks.json)`,
164
- file: path.join(userDir, "tasks.json"),
165
- write: "print",
170
+ file: taskFile,
171
+ write: exists(taskFile) ? "print" : "create",
166
172
  snippet: json({
167
173
  version: "2.0.0",
168
174
  tasks: [
@@ -190,13 +196,24 @@ export function buildEditorSetup(editor, launch, ctx = {}) {
190
196
  label: "VS Code MCP server",
191
197
  file: null,
192
198
  write: "command",
193
- run: { cmd: "code", args: ["--add-mcp", addMcp] },
199
+ run: {
200
+ cmd: "code",
201
+ args: ["--add-mcp", addMcp],
202
+ // macOS: `code` is only on PATH after "Install 'code' command in PATH".
203
+ fallbacks:
204
+ platform === "darwin"
205
+ ? [
206
+ "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code",
207
+ path.join(home, "Applications", "Visual Studio Code.app", "Contents", "Resources", "app", "bin", "code"),
208
+ ]
209
+ : [],
210
+ },
194
211
  snippet: shellJoin(["code", "--add-mcp", addMcp], platform),
195
212
  },
196
213
  ];
197
214
  return {
198
215
  id: editor,
199
- name: isCursor ? "Cursor" : "VS Code",
216
+ name: isCursor ? "Cursor" : "VS Code (Copilot)",
200
217
  detected: exists(userDir) || (isCursor && exists(path.join(home, ".cursor"))),
201
218
  items,
202
219
  };
@@ -215,16 +232,37 @@ export function buildEditorSetup(editor, launch, ctx = {}) {
215
232
  write: "command",
216
233
  run: {
217
234
  cmd: "claude",
218
- args: ["mcp", "add", MCP_KEY, "--", server.command, ...server.args],
235
+ args: ["mcp", "add", "--scope", "user", MCP_KEY, "--", server.command, ...server.args],
219
236
  },
220
237
  snippet: shellJoin(
221
- ["claude", "mcp", "add", MCP_KEY, "--", server.command, ...server.args],
238
+ ["claude", "mcp", "add", "--scope", "user", MCP_KEY, "--", server.command, ...server.args],
222
239
  platform,
223
240
  ),
224
241
  },
225
242
  ],
226
243
  };
227
244
 
245
+ case "copilot-cli": {
246
+ // GitHub Copilot in the terminal keeps its own list (~/.copilot/mcp-config.json),
247
+ // separate from VS Code's; its CLI writes it.
248
+ const args = ["mcp", "add", MCP_KEY, "--", server.command, ...server.args];
249
+ return {
250
+ id: "copilot-cli",
251
+ name: "Copilot CLI",
252
+ detected: exists(path.join(home, ".copilot")),
253
+ items: [
254
+ {
255
+ kind: "mcp",
256
+ label: "Copilot CLI MCP server",
257
+ file: null,
258
+ write: "command",
259
+ run: { cmd: "copilot", args },
260
+ snippet: shellJoin(["copilot", ...args], platform),
261
+ },
262
+ ],
263
+ };
264
+ }
265
+
228
266
  case "claude-desktop": {
229
267
  const file = path.join(r.appData, "Claude", "claude_desktop_config.json");
230
268
  return {
@@ -268,13 +306,122 @@ export function applySetupItem(item, { stdio = "inherit" } = {}) {
268
306
  if (item.write === "command") {
269
307
  // Windows: code/claude are .cmd shims, which need the shell; pass one
270
308
  // pre-quoted command line so JSON arguments survive cmd.exe.
271
- const result =
309
+ let result =
272
310
  process.platform === "win32"
273
311
  ? spawnSync(item.snippet, { stdio, shell: true })
274
312
  : spawnSync(item.run.cmd, item.run.args, { stdio });
313
+ for (const cmd of item.run.fallbacks ?? []) {
314
+ if (result.error?.code !== "ENOENT") break;
315
+ if (fs.existsSync(cmd)) result = spawnSync(cmd, item.run.args, { stdio });
316
+ }
275
317
  return result.status === 0
276
318
  ? { done: true, message: `ran: ${item.snippet}` }
277
319
  : { done: false, message: `could not run "${item.run.cmd}" — run the command yourself` };
278
320
  }
279
321
  return { done: false, message: "existing file: paste the snippet yourself" };
280
322
  }
323
+
324
+ // ── Status (doctor) ──────────────────────────────────────────────────────────
325
+
326
+ const readText = (file) => {
327
+ try {
328
+ return fs.readFileSync(file, "utf8");
329
+ } catch {
330
+ return null;
331
+ }
332
+ };
333
+
334
+ /** Task file: names our package. Settings/MCP file: has a "markdown-pdf" entry. */
335
+ const hasTask = (text) => text !== null && text.includes(SERVER_NAME);
336
+ const hasMcpKey = (text) => text !== null && text.includes(`"${MCP_KEY}"`);
337
+
338
+ /**
339
+ * Claude Code keeps user-scope servers at the top of ~/.claude.json and
340
+ * local-scope ones per project. "project" = only set up for some folders.
341
+ * @returns {boolean|"project"}
342
+ */
343
+ function claudeCodeMcp(file) {
344
+ const text = readText(file);
345
+ if (text === null) return false;
346
+ try {
347
+ const data = JSON.parse(text);
348
+ if (data?.mcpServers?.[MCP_KEY]) return true;
349
+ const inProject = Object.values(data?.projects ?? {}).some((p) => p?.mcpServers?.[MCP_KEY]);
350
+ return inProject ? "project" : false;
351
+ } catch {
352
+ return hasMcpKey(text);
353
+ }
354
+ }
355
+
356
+ /**
357
+ * What is set up in each editor: read-only, for `doctor`.
358
+ * `task` / `mcp` are undefined when the editor has no such thing.
359
+ * `warnings` flags configs known to cause trouble (an old settings override).
360
+ * @param {{home?: string, platform?: string, env?: NodeJS.ProcessEnv}} [ctx]
361
+ * @returns {{id: string, name: string, detected: boolean, task?: boolean, mcp?: boolean|"project", warnings: string[]}[]}
362
+ */
363
+ export function editorStatus(ctx = {}) {
364
+ const home = ctx.home ?? os.homedir();
365
+ const platform = ctx.platform ?? process.platform;
366
+ const env = ctx.env ?? process.env;
367
+ const r = roots({ home, platform, env });
368
+
369
+ return EDITOR_IDS.map((id) => {
370
+ const { name, detected } = buildEditorSetup(id, { command: "npx", args: [] }, { home, platform, env });
371
+ const out = { id, name, detected, warnings: [] };
372
+ let taskFile = null;
373
+ switch (id) {
374
+ case "zed":
375
+ taskFile = path.join(r.zed, "tasks.json");
376
+ out.mcp = hasMcpKey(readText(path.join(r.zed, "settings.json")));
377
+ break;
378
+ case "vscode":
379
+ case "cursor": {
380
+ const userDir = path.join(r.userData, id === "cursor" ? "Cursor" : "Code", "User");
381
+ // ~/.cursor alone = Cursor Agent CLI without the app: no task to offer.
382
+ if (id === "vscode" || fs.existsSync(userDir)) taskFile = path.join(userDir, "tasks.json");
383
+ out.mcp = hasMcpKey(
384
+ readText(id === "cursor" ? path.join(home, ".cursor", "mcp.json") : path.join(userDir, "mcp.json")),
385
+ );
386
+ break;
387
+ }
388
+ case "claude-code":
389
+ out.mcp = claudeCodeMcp(path.join(home, ".claude.json"));
390
+ break;
391
+ case "claude-desktop":
392
+ out.mcp = hasMcpKey(readText(path.join(r.appData, "Claude", "claude_desktop_config.json")));
393
+ break;
394
+ case "copilot-cli":
395
+ out.mcp = hasMcpKey(readText(path.join(home, ".copilot", "mcp-config.json")));
396
+ break;
397
+ }
398
+ if (taskFile) {
399
+ const text = readText(taskFile);
400
+ out.task = hasTask(text);
401
+ if (out.task && text.includes("MARKDOWN_PDF_SETTINGS")) {
402
+ out.warnings.push(
403
+ `${taskFile} sets MARKDOWN_PDF_SETTINGS, which replaces your settings file`,
404
+ );
405
+ }
406
+ }
407
+ if (out.task || out.mcp) out.detected = true; // set up, even if its folder moved
408
+ return out;
409
+ });
410
+ }
411
+
412
+ /** What a setup item adds, in words. */
413
+ export const ITEM_LABELS = { task: "export task", mcp: "AI tools" };
414
+
415
+ /**
416
+ * Items of one editor that are not set up yet, given its editorStatus() entry.
417
+ * Claude Code set up only for some folders ("project") still counts as to do;
418
+ * a kind the status does not list is skipped (it does not apply here).
419
+ * @param {{items: SetupItem[]}} setup
420
+ * @param {{task?: boolean, mcp?: boolean|"project"}|undefined} status
421
+ * @returns {SetupItem[]}
422
+ */
423
+ export function pendingItems(setup, status) {
424
+ if (!status) return [...setup.items];
425
+ // A kind missing from the status does not apply here (Cursor CLI without the app).
426
+ return setup.items.filter((item) => item.kind in status && status[item.kind] !== true);
427
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @fileoverview Page break markers. A document can start a new page with any
3
+ * of these, so people can write what they already know:
4
+ *
5
+ * <div class="page"></div> (also page-break, pagebreak, page_break,
6
+ * <div class="new-page"></div> new-page, newpage, break-page)
7
+ * <hr class="page-break">
8
+ * <!-- page-break --> (also pagebreak, page_break, new-page,
9
+ * newpage, page)
10
+ * <div style="page-break-after: always"></div> (plain CSS, always worked)
11
+ *
12
+ * `<div class="page-break-before">` breaks before the element instead.
13
+ */
14
+
15
+ export const PAGE_BREAK_CLASSES = [
16
+ "page",
17
+ "page-break",
18
+ "pagebreak",
19
+ "page_break",
20
+ "new-page",
21
+ "newpage",
22
+ "break-page",
23
+ ];
24
+
25
+ /** CSS that makes the classes work. Always added, even without the default stylesheet. */
26
+ export const PAGE_BREAK_CSS =
27
+ `${PAGE_BREAK_CLASSES.map((c) => `.${c}`).join(",")}{break-after:page;page-break-after:always}` +
28
+ `.page-break-before{break-before:page;page-break-before:always}`;
29
+
30
+ const COMMENT = /^<!--\s*(?:page[-_ ]?break|new[-_ ]?page|page)\s*-->\s*$/i;
31
+
32
+ /**
33
+ * markdown-it plugin: turn `<!-- page-break -->` style comments into a page
34
+ * break element. Comments inside code blocks are untouched (they are not html tokens).
35
+ * @param {import("markdown-it")} md
36
+ */
37
+ export function pageBreakComments(md) {
38
+ md.core.ruler.push("page_break_comments", (state) => {
39
+ for (const token of state.tokens) {
40
+ if (token.type === "html_block" && COMMENT.test(token.content.trim())) {
41
+ token.content = '<div class="page-break"></div>\n';
42
+ } else if (token.type === "inline" && token.children) {
43
+ for (const child of token.children) {
44
+ if (child.type === "html_inline" && COMMENT.test(child.content.trim())) {
45
+ child.content = '<span class="page-break"></span>';
46
+ }
47
+ }
48
+ }
49
+ }
50
+ });
51
+ }
@@ -10,7 +10,7 @@ import { LOOKS, FONTS, TEMPLATES } from "./looks.mjs";
10
10
  import { BUILTIN_PLACEHOLDERS, ELEMENT_TYPES, SHORTHAND_MAPPINGS } from "./types.mjs";
11
11
 
12
12
  export const SETTINGS_SCHEMA_URL =
13
- "https://matinfo.github.io/markdown-pdf-export/schema/settings.schema.json";
13
+ "https://markdown-pdf.matinfo.tech/schema/settings.schema.json";
14
14
 
15
15
  /** Export options that make no sense in a settings file. */
16
16
  const CALL_ONLY = new Set(["input_path", "output_path"]);
@@ -36,7 +36,14 @@ import {
36
36
  readSettingsFile,
37
37
  userSettingsPath,
38
38
  } from "./settings-loader.mjs";
39
- import { EDITOR_IDS, applySetupItem, buildEditorSetup, launchSpec } from "./editor-setup.mjs";
39
+ import {
40
+ EDITOR_IDS,
41
+ applySetupItem,
42
+ buildEditorSetup,
43
+ editorStatus,
44
+ launchSpec,
45
+ pendingItems,
46
+ } from "./editor-setup.mjs";
40
47
  import { IMAGE_FORMATS } from "./types.mjs";
41
48
 
42
49
  const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
@@ -393,15 +400,27 @@ export async function startStudio(opts = {}) {
393
400
 
394
401
  if (req.method === "GET" && route === "/api/state") return send(res, 200, state());
395
402
  if (req.method === "GET" && route === "/api/editors") {
403
+ const status = Object.fromEntries(editorStatus().map((e) => [e.id, e]));
396
404
  return send(
397
405
  res,
398
406
  200,
399
- editors().map((e) => ({
400
- id: e.id,
401
- name: e.name,
402
- detected: e.detected,
403
- items: e.items.map((i) => ({ label: i.label, file: i.file ?? null, snippet: i.snippet, write: i.write })),
404
- })),
407
+ editors().map((e) => {
408
+ const todo = new Set(pendingItems(e, status[e.id]));
409
+ return {
410
+ id: e.id,
411
+ name: e.name,
412
+ detected: e.detected || Boolean(status[e.id]?.detected),
413
+ items: e.items.map((i) => ({
414
+ kind: i.kind,
415
+ label: i.label,
416
+ file: i.file ?? null,
417
+ snippet: i.snippet,
418
+ write: i.write,
419
+ // not set up yet, and applies on this computer
420
+ pending: todo.has(i),
421
+ })),
422
+ };
423
+ }),
405
424
  );
406
425
  }
407
426
  if (req.method === "GET" && route === "/api/check") {
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Tiny terminal colours, no dependency. On only for a TTY;
3
+ * NO_COLOR turns it off, FORCE_COLOR (≠ "0") turns it on. See no-color.org.
4
+ */
5
+
6
+ /**
7
+ * @param {{stream?: {isTTY?: boolean}, env?: NodeJS.ProcessEnv}} [opts]
8
+ */
9
+ export function makeStyle({ stream = process.stdout, env = process.env } = {}) {
10
+ const enabled = env.FORCE_COLOR
11
+ ? env.FORCE_COLOR !== "0"
12
+ : !env.NO_COLOR && Boolean(stream.isTTY) && env.TERM !== "dumb";
13
+ const wrap = (open, close) => (text) =>
14
+ enabled ? `\x1b[${open}m${text}\x1b[${close}m` : String(text);
15
+ return {
16
+ enabled,
17
+ bold: wrap(1, 22),
18
+ dim: wrap(2, 22),
19
+ red: wrap(31, 39),
20
+ green: wrap(32, 39),
21
+ yellow: wrap(33, 39),
22
+ cyan: wrap(36, 39),
23
+ };
24
+ }
25
+
26
+ /** No colours: for tests, JSON, logs. */
27
+ export const plain = makeStyle({ stream: {}, env: { NO_COLOR: "1" } });
package/lib/types.mjs CHANGED
@@ -331,4 +331,4 @@ export const DEFAULT_FOOTER = Object.freeze({
331
331
  * VitePress documentation URL.
332
332
  * @type {string}
333
333
  */
334
- export const DOCS_URL = "https://matinfo.github.io/markdown-pdf-export/";
334
+ export const DOCS_URL = "https://markdown-pdf.matinfo.tech/";
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "markdown-pdf-export",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Markdown to PDF with your header, footer, page numbers and logo. Design pages in Studio, export from VS Code, Zed, Cursor, Claude or any MCP client, or the command line.",
5
5
  "type": "module",
6
- "mcpName": "io.github.matinfo/markdown-pdf-export",
6
+ "mcpName": "io.github.matinfo-tech/markdown-pdf-export",
7
7
  "main": "export.mjs",
8
8
  "exports": {
9
9
  ".": "./export.mjs",
@@ -83,15 +83,20 @@
83
83
  "documentation",
84
84
  "report"
85
85
  ],
86
- "author": "Mat <mat@matinfo.ch>",
86
+ "author": {
87
+ "name": "Matinfo",
88
+ "email": "dev@matinfo.tech",
89
+ "url": "https://matinfo.tech"
90
+ },
87
91
  "license": "MIT",
88
92
  "repository": {
89
93
  "type": "git",
90
- "url": "git+https://github.com/matinfo/markdown-pdf-export.git"
94
+ "url": "git+https://github.com/matinfo-tech/markdown-pdf-export.git"
91
95
  },
92
- "homepage": "https://matinfo.github.io/markdown-pdf-export/",
96
+ "homepage": "https://markdown-pdf.matinfo.tech/",
93
97
  "bugs": {
94
- "url": "https://github.com/matinfo/markdown-pdf-export/issues"
98
+ "url": "https://github.com/matinfo-tech/markdown-pdf-export/issues",
99
+ "email": "dev@matinfo.tech"
95
100
  },
96
101
  "packageManager": "npm@11.12.1",
97
102
  "devDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://matinfo.github.io/markdown-pdf-export/schema/settings.schema.json",
3
+ "$id": "https://markdown-pdf.matinfo.tech/schema/settings.schema.json",
4
4
  "title": "markdown-pdf-export settings",
5
5
  "description": "User settings (~/.config/markdown-pdf-export/settings.json) or project settings (.markdown-pdf.json).",
6
6
  "type": "object",
package/studio/app.mjs CHANGED
@@ -481,11 +481,18 @@ async function save() {
481
481
  }
482
482
  }
483
483
 
484
+ const EDITOR_ORDER = ["vscode", "copilot-cli", "claude-code", "claude-desktop", "cursor", "zed"];
485
+ const EDITOR_NOTES = {
486
+ vscode: "Works with GitHub Copilot Chat in agent mode.",
487
+ "copilot-cli": "For GitHub Copilot in the terminal (the copilot command).",
488
+ };
489
+ let editorTab = "";
490
+
484
491
  async function openEditors() {
485
492
  const dialog = $("editors");
486
493
  const list = $("editors-list");
487
494
  list.replaceChildren(el("p", { class: "hint", text: "Looking for your editors…" }));
488
- dialog.showModal();
495
+ if (!dialog.open) dialog.showModal();
489
496
  let editors;
490
497
  try {
491
498
  editors = await api("/api/editors");
@@ -498,19 +505,11 @@ async function openEditors() {
498
505
  el(
499
506
  "div",
500
507
  { class: "editor" },
501
- el("h3", { text: editor.name }, editor.detected ? el("small", { text: "found on this computer" }) : null),
508
+ editor.detected ? el("p", { class: "found-note", text: `${editor.name} is on this computer.` }) : null,
509
+ EDITOR_NOTES[editor.id] ? el("p", { class: "editor-note", text: EDITOR_NOTES[editor.id] }) : null,
502
510
  ...editor.items.map((item, index) => {
503
511
  const result = el("div", { class: "result", role: "status" });
504
- const copy = el("button", {
505
- type: "button",
506
- class: "btn small",
507
- text: "Copy",
508
- onclick: async () => {
509
- await navigator.clipboard.writeText(item.snippet);
510
- copy.textContent = "Copied";
511
- setTimeout(() => (copy.textContent = "Copy"), 1500);
512
- },
513
- });
512
+ const copy = copyButton(item.snippet);
514
513
  const auto =
515
514
  item.write === "print"
516
515
  ? null
@@ -543,13 +542,170 @@ async function openEditors() {
543
542
  }),
544
543
  );
545
544
 
546
- const found = editors.filter((e) => e.detected);
547
- const others = editors.filter((e) => !e.detected);
548
- const nodes = (found.length ? found : others).map(card);
549
- if (found.length && others.length) {
550
- nodes.push(el("details", { class: "others" }, el("summary", { text: "Other editors" }), ...others.map(card)));
545
+ // One tab per editor, in a fixed order; open on the first one found on this computer.
546
+ const sorted = EDITOR_ORDER.map((id) => editors.find((e) => e.id === id)).filter(Boolean);
547
+ for (const e of editors) if (!sorted.includes(e)) sorted.push(e);
548
+ let current = sorted.find((e) => e.id === editorTab) ?? sorted.find((e) => e.detected) ?? sorted[0];
549
+
550
+ const tabs = el("div", { class: "tabs", role: "tablist", "aria-label": "Editors" });
551
+ const panel = el("div", { class: "tab-panel", role: "tabpanel" });
552
+ const buttons = new Map();
553
+
554
+ const select = (editor, focus = false) => {
555
+ current = editor;
556
+ editorTab = editor.id;
557
+ for (const [id, button] of buttons) {
558
+ const on = id === editor.id;
559
+ button.setAttribute("aria-selected", String(on));
560
+ button.tabIndex = on ? 0 : -1;
561
+ if (on && focus) button.focus();
562
+ }
563
+ panel.setAttribute("aria-labelledby", `tab-${editor.id}`);
564
+ panel.replaceChildren(card(editor));
565
+ };
566
+
567
+ sorted.forEach((editor, i) => {
568
+ const button = el(
569
+ "button",
570
+ {
571
+ type: "button",
572
+ role: "tab",
573
+ id: `tab-${editor.id}`,
574
+ class: "tab",
575
+ onclick: () => select(editor),
576
+ onkeydown: (event) => {
577
+ const step = { ArrowRight: 1, ArrowLeft: -1 }[event.key];
578
+ if (!step) return;
579
+ event.preventDefault();
580
+ select(sorted[(i + step + sorted.length) % sorted.length], true);
581
+ },
582
+ },
583
+ editor.name,
584
+ editor.detected ? el("span", { class: "found", title: "Found on this computer", "aria-label": "found on this computer" }) : null,
585
+ );
586
+ buttons.set(editor.id, button);
587
+ tabs.append(button);
588
+ });
589
+
590
+ const found = sorted.filter((e) => e.detected);
591
+ const manual = el(
592
+ "details",
593
+ { class: "manual", open: found.length === 0 },
594
+ el("summary", { text: found.length ? "All editors and manual steps" : "Pick your editor" }),
595
+ tabs,
596
+ panel,
597
+ );
598
+ list.replaceChildren(quickSetup(found), manual);
599
+ select(current);
600
+ }
601
+
602
+ function copyButton(text) {
603
+ const button = el("button", {
604
+ type: "button",
605
+ class: "btn small",
606
+ text: "Copy",
607
+ onclick: async () => {
608
+ await navigator.clipboard.writeText(text);
609
+ button.textContent = "Copied";
610
+ setTimeout(() => (button.textContent = "Copy"), 1500);
611
+ },
612
+ });
613
+ return button;
614
+ }
615
+
616
+ const KIND_LABEL = { task: "export task", mcp: "AI tools" };
617
+
618
+ /**
619
+ * Editors found on this computer, one switch each (on by default). Already
620
+ * set-up parts are skipped; files that exist are never edited — the person
621
+ * gets the snippet to paste instead.
622
+ */
623
+ function quickSetup(found) {
624
+ const box = el("section", { class: "quick", "aria-label": "Editors found on this computer" });
625
+ if (found.length === 0) {
626
+ box.append(el("p", { class: "hint", text: "No editor found on this computer. Pick yours below." }));
627
+ return box;
628
+ }
629
+ box.append(el("h3", { text: "Found on this computer" }));
630
+
631
+ const rows = found.map((editor) => {
632
+ const todo = editor.items.map((item, index) => ({ item, index })).filter((x) => x.item.pending);
633
+ const result = el("div", { class: "quick-result", role: "status" });
634
+ if (todo.length === 0) {
635
+ const row = el(
636
+ "div",
637
+ { class: "quick-row done" },
638
+ el("span", { class: "tick", "aria-hidden": "true", text: "✓" }),
639
+ el("span", { class: "quick-name", text: editor.name }),
640
+ el("span", { class: "quick-what", text: "Already set up" }),
641
+ );
642
+ return { row, toggle: null };
643
+ }
644
+ const id = `quick-${editor.id}`;
645
+ const toggle = el("input", { type: "checkbox", role: "switch", class: "switch", id, checked: true });
646
+ const what = [...new Set(todo.map((x) => KIND_LABEL[x.item.kind]))].join(" + ");
647
+ const row = el(
648
+ "div",
649
+ { class: "quick-row" },
650
+ toggle,
651
+ el("label", { for: id, class: "quick-name", text: editor.name }),
652
+ el("span", { class: "quick-what", text: what }),
653
+ result,
654
+ );
655
+ return { row, toggle, editor, todo, result };
656
+ });
657
+
658
+ const pending = rows.filter((r) => r.toggle);
659
+ box.append(...rows.map((r) => r.row));
660
+ if (pending.length === 0) {
661
+ box.append(el("p", { class: "hint", text: "Everything found here is set up." }));
662
+ return box;
551
663
  }
552
- list.replaceChildren(...nodes);
664
+
665
+ const go = el("button", { type: "button", class: "btn primary" });
666
+ const selected = () => pending.filter((r) => r.toggle.checked && !r.toggle.disabled);
667
+ const refresh = () => {
668
+ const n = selected().length;
669
+ go.textContent = n ? `Set up ${n} editor${n > 1 ? "s" : ""}` : "Nothing selected";
670
+ go.disabled = n === 0;
671
+ };
672
+ for (const r of pending) r.toggle.addEventListener("change", refresh);
673
+
674
+ const line = (ok, text, title) => el("p", { class: ok ? "ok" : "bad", text: `${ok ? "✓" : "✗"} ${text}`, title });
675
+ const paste = (item, why) =>
676
+ el(
677
+ "div",
678
+ { class: "paste" },
679
+ el("div", { class: "step-head" }, el("span", { text: why }), copyButton(item.snippet)),
680
+ el("pre", { text: item.snippet }),
681
+ );
682
+
683
+ go.addEventListener("click", async () => {
684
+ go.disabled = true;
685
+ for (const r of selected()) {
686
+ r.toggle.disabled = true;
687
+ r.result.replaceChildren();
688
+ for (const { item, index } of r.todo) {
689
+ const label = KIND_LABEL[item.kind];
690
+ if (item.write === "print") {
691
+ r.result.append(paste(item, `${label}: paste this into ${item.file}`));
692
+ continue;
693
+ }
694
+ try {
695
+ const { done, message } = await api("/api/editors/apply", { method: "POST", json: { id: r.editor.id, index } });
696
+ r.result.append(line(done, done ? `${label} added` : `${label}: ${message}`, message));
697
+ if (!done) r.result.append(paste(item, "Run or add this yourself:"));
698
+ } catch (error) {
699
+ r.result.append(line(false, `${label}: ${error.message}`), paste(item, "Run or add this yourself:"));
700
+ }
701
+ }
702
+ }
703
+ refresh();
704
+ if (selected().length === 0) go.textContent = "Done";
705
+ });
706
+ refresh();
707
+ box.append(el("div", { class: "quick-foot" }, go));
708
+ return box;
553
709
  }
554
710
 
555
711
  // ── start ───────────────────────────────────────────────────────────────────