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/README.md +1 -1
- package/dist/_chunks/exporter.mjs +3 -15
- package/dist/_chunks/server.mjs +1142 -1518
- package/dist/cli/main.mjs +42 -16
- package/package.json +16 -17
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,
|
|
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)
|
|
277
|
-
|
|
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(
|
|
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://"))
|
|
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
|
|
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.
|
|
33
|
+
"@speed-highlight/core": "^1.2.15",
|
|
34
34
|
"giget": "^3.1.2",
|
|
35
|
-
"md4x": "
|
|
36
|
-
"
|
|
37
|
-
"
|
|
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": "
|
|
42
|
-
"@typescript/native-preview": "
|
|
43
|
-
"@vitest/coverage-v8": "
|
|
44
|
-
"automd": "
|
|
45
|
-
"changelogen": "
|
|
46
|
-
"obuild": "
|
|
47
|
-
"oxfmt": "
|
|
48
|
-
"oxlint": "
|
|
49
|
-
"typescript": "
|
|
50
|
-
"vitest": "
|
|
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.
|
|
51
|
+
"packageManager": "pnpm@10.32.1"
|
|
53
52
|
}
|