mdzilla 0.0.5 → 0.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/dist/cli/main.mjs CHANGED
@@ -6,7 +6,7 @@ import { parseMeta, renderToAnsi, renderToText } from "md4x";
6
6
  import { parseArgs } from "node:util";
7
7
  import { isAgent } from "std-env";
8
8
  import { highlightText } from "@speed-highlight/core/terminal";
9
- import { exec, execSync } from "node:child_process";
9
+ import { exec, execFile } from "node:child_process";
10
10
  //#region src/cli/_ansi.ts
11
11
  const noColor = !!(process.env.NO_COLOR || process.env.TERM === "dumb" || !process.stdout.isTTY || isAgent);
12
12
  const ESC = "\x1B[";
@@ -273,8 +273,10 @@ async function pageMode(docs, pagePath, plain) {
273
273
  title: parseMeta(raw).title || slug,
274
274
  order: 0
275
275
  };
276
- if (plain) process.stdout.write(renderToText(raw) + "\n");
277
- else {
276
+ if (plain) {
277
+ process.stdout.write(renderToText(raw) + "\n");
278
+ if (isAgent) process.stdout.write(agentTrailer(docs, normalized));
279
+ } else {
278
280
  const lines = await renderContent(raw, navEntry, 0);
279
281
  process.stdout.write(lines.join("\n") + "\n");
280
282
  }
@@ -285,20 +287,54 @@ async function plainMode(docs, pagePath) {
285
287
  console.log("No pages found.");
286
288
  return;
287
289
  }
290
+ if (isAgent && pagePath) {
291
+ const normalized = pagePath.startsWith("/") ? pagePath : "/" + pagePath;
292
+ const resolved = await docs.resolvePage(normalized);
293
+ if (resolved.raw) process.stdout.write(renderToText(resolved.raw) + "\n");
294
+ else process.stdout.write(`Page not found: ${pagePath}\n`);
295
+ process.stdout.write(agentTrailer(docs, normalized));
296
+ return;
297
+ }
288
298
  const tocLines = ["Table of Contents", ""];
289
299
  for (const f of navigable) {
290
300
  const indent = " ".repeat(f.depth);
291
301
  tocLines.push(`${indent}- [${f.entry.title}](${f.entry.path})`);
292
302
  }
293
303
  process.stdout.write(tocLines.join("\n") + "\n");
294
- let targetEntry = navigable[0];
295
304
  if (pagePath) {
296
305
  const resolved = await docs.resolvePage(pagePath);
297
306
  if (resolved.raw) process.stdout.write(renderToText(resolved.raw) + "\n\n");
298
307
  } else {
299
- const raw = await docs.getContent(targetEntry);
308
+ const raw = await docs.getContent(navigable[0]);
300
309
  if (raw) process.stdout.write(renderToText(raw) + "\n\n");
301
310
  }
311
+ if (isAgent && navigable.length > 1) process.stdout.write("\n---\n\nTo read a specific page from the table of contents above, run this command again with `--page <path>`.\n");
312
+ }
313
+ function agentTrailer(docs, currentPath) {
314
+ const pages = docs.pages;
315
+ if (pages.length <= 1) return "";
316
+ const normalized = currentPath?.startsWith("/") ? currentPath : currentPath ? "/" + currentPath : void 0;
317
+ const otherPages = pages.filter((p) => p.entry.path !== normalized);
318
+ if (otherPages.length === 0) return "";
319
+ return "\n" + [
320
+ "---",
321
+ "",
322
+ "Other available pages:",
323
+ ...otherPages.map((p) => ` - [${p.entry.title}](${p.entry.path})`),
324
+ "",
325
+ "To read a specific page, run this command again with `--page <path>`.",
326
+ "To view the full table of contents, run this command without `--page`.",
327
+ ""
328
+ ].join("\n");
329
+ }
330
+ //#endregion
331
+ //#region src/cli/_utils.ts
332
+ function openInBrowser(url) {
333
+ const parsed = new URL(url);
334
+ if (parsed.hostname === "[::]" || parsed.hostname === "[::1]" || parsed.hostname === "127.0.0.1") parsed.hostname = "localhost";
335
+ url = parsed.href;
336
+ if (process.platform === "win32") exec(`start "" ${JSON.stringify(url)}`, () => {});
337
+ else execFile(process.platform === "darwin" ? "open" : "xdg-open", [url], () => {});
302
338
  }
303
339
  //#endregion
304
340
  //#region src/cli/interactive/nav.ts
@@ -603,9 +639,7 @@ async function interactiveMode(docs) {
603
639
  if (line < contentScroll || line >= contentScroll + rows - 2) contentScroll = Math.max(0, Math.min(line - Math.floor(rows / 3), contentLines.length - rows + 2));
604
640
  };
605
641
  const activateLink = (url) => {
606
- if (url.startsWith("http://") || url.startsWith("https://")) try {
607
- execSync(`open ${JSON.stringify(url)}`, { stdio: "ignore" });
608
- } catch {}
642
+ if (url.startsWith("http://") || url.startsWith("https://")) openInBrowser(url);
609
643
  else {
610
644
  const target = url.replace(/^\.\//, "/").replace(/\/$/, "");
611
645
  const idx = flat.indexOf(docs.findByPath(target));
@@ -730,14 +764,6 @@ async function interactiveMode(docs) {
730
764
  }
731
765
  }
732
766
  //#endregion
733
- //#region src/cli/_utils.ts
734
- function openInBrowser(url) {
735
- const parsed = new URL(url);
736
- if (parsed.hostname === "[::]" || parsed.hostname === "[::1]" || parsed.hostname === "127.0.0.1") parsed.hostname = "localhost";
737
- url = parsed.href;
738
- exec(process.platform === "win32" ? `start ${url}` : process.platform === "darwin" ? `open ${url}` : `xdg-open ${url}`, () => {});
739
- }
740
- //#endregion
741
767
  //#region src/cli/main.ts
742
768
  async function main() {
743
769
  process.stdout.on("error", (err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdzilla",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "pi0/mdzilla",
@@ -30,24 +30,23 @@
30
30
  "typecheck": "tsgo --noEmit --skipLibCheck"
31
31
  },
32
32
  "dependencies": {
33
- "@speed-highlight/core": "^1.2.14",
33
+ "@speed-highlight/core": "^1.2.15",
34
34
  "giget": "^3.1.2",
35
- "md4x": ">=0.0.22",
36
- "mdream": "^0.16.0",
37
- "srvx": "^0.11.9",
38
- "std-env": "4.0.0-rc.1"
35
+ "md4x": "^0.0.25",
36
+ "srvx": "^0.11.13",
37
+ "std-env": "^4.0.0"
39
38
  },
40
39
  "devDependencies": {
41
- "@types/node": "latest",
42
- "@typescript/native-preview": "latest",
43
- "@vitest/coverage-v8": "latest",
44
- "automd": "latest",
45
- "changelogen": "latest",
46
- "obuild": "latest",
47
- "oxfmt": "latest",
48
- "oxlint": "latest",
49
- "typescript": "latest",
50
- "vitest": "latest"
40
+ "@types/node": "^25.5.0",
41
+ "@typescript/native-preview": "^7.0.0-dev.20260324.1",
42
+ "@vitest/coverage-v8": "^4.1.1",
43
+ "automd": "^0.4.3",
44
+ "changelogen": "^0.6.2",
45
+ "obuild": "^0.4.32",
46
+ "oxfmt": "^0.41.0",
47
+ "oxlint": "^1.56.0",
48
+ "typescript": "^6.0.2",
49
+ "vitest": "^4.1.1"
51
50
  },
52
- "packageManager": "pnpm@10.29.3"
51
+ "packageManager": "pnpm@10.32.1"
53
52
  }