cudoc-html 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cudoment
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # cudoc-html
2
+
3
+ Add an optional HTML output alongside your documentation host (Next.js with MDX, Docusaurus, Nextra or VitePress), reusing its collected content and prepared embeds. Keep the primary site and document sources unchanged. The generated directory can be deployed or shared as local files, and can also be built without another host.
4
+
5
+ ESM · Node.js 20+
6
+
7
+ ```sh
8
+ npm install @cudoment/cudoc cudoc-html
9
+ ```
10
+
11
+ ```js
12
+ import { buildSite } from "cudoc-html"
13
+
14
+ const result = buildSite({
15
+ sourceRoot: "docs",
16
+ outDir: "site",
17
+ title: "Product documentation",
18
+ syntax: {},
19
+ })
20
+ ```
21
+
22
+ The CLI equivalent is `npx cudoc-html build docs --out-dir site`. Open `site/index.html` and share the whole directory. The builder handles collection, embeds, local assets, navigation, TOC and code highlighting. Use a nonexistent output path initially; existing output must be owned by cudoc. The generated shell needs no JavaScript or CDN, and does not execute React components.
23
+
24
+ To export alongside an existing site, first run that host's collector and embed preparation, then reuse its library:
25
+
26
+ ```js
27
+ buildSite({
28
+ sourceRoot: "docs",
29
+ library: ".cudoc/documents",
30
+ outDir: "shared-html",
31
+ links: "host",
32
+ hostUrl: "https://docs.example.com/project/",
33
+ assetDirs: ["public"],
34
+ })
35
+ ```
36
+
37
+ `library` reads the collected AST and prepared embeds without recompiling or modifying them. Recollect after edits. Keep syntax/compiler options in the collector, and use separate host and HTML output directories. Add `assetDirs` for host asset roots such as `public` or `static`; use `renderOptions.components` for explicit HTML rendering of custom component nodes.
38
+
39
+ Choose `links: "relative"` (default) for local files, `"host"` for the primary deployment's collected document routes, or `"none"` to remove all hyperlinks while preserving labels and formatting. The policy covers body content, embeds, raw HTML, navigation and TOC. Local images and CSS remain local; `host` keeps external URLs, while `none` removes those hyperlinks too. CLI equivalents are `--library`, `--links`, `--host-url` and repeatable `--asset-dir`.
40
+
41
+ Choose `host`, `cudoc` or `both` independently for `headingAnchor`, `badge`, `tableCellList`, `callout` and `link`. The representative callout is `> [!NOTE] Title`. Authors do not register cudoc React components in the recommended setup. Syntax-only rendering needs no stored JSON; cross-document embedding requires document collection.
42
+
43
+ - [Usage guide](https://github.com/cudoment/cudoc/tree/main/docs/html.md) · [한국어 가이드](https://github.com/cudoment/cudoc/tree/main/docs/html.ko.md)
44
+ - [Markdown syntax](https://github.com/cudoment/cudoc/tree/main/docs/syntax.md)
45
+ - [Embedding](https://github.com/cudoment/cudoc/tree/main/docs/embedding.md)
46
+ - [API reference](https://github.com/cudoment/cudoc/tree/main/docs/api-reference/README.md)
47
+ - [Runnable examples](https://github.com/cudoment/cudoc/tree/main/examples/README.md)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { buildSite } from "./index.js";
6
+ try {
7
+ const args = process.argv.slice(2);
8
+ if (args[0] !== "build")
9
+ throw new Error("Usage: cudoc-html build [sourceRoot] [--out-dir site] [--config config.mjs] [--library directory] [--links relative|host|none] [--host-url https://example.com/] [--asset-dir directory]");
10
+ const options = {};
11
+ const assetDirs = [];
12
+ let sourceRoot;
13
+ for (let i = 1; i < args.length; i++) {
14
+ if ([
15
+ "--out-dir",
16
+ "--config",
17
+ "--library",
18
+ "--links",
19
+ "--host-url",
20
+ "--asset-dir",
21
+ ].includes(args[i])) {
22
+ const key = args[i];
23
+ if (!args[i + 1] || args[i + 1].startsWith("--"))
24
+ throw new Error(`Missing value for ${key}`);
25
+ const value = args[++i];
26
+ if (key === "--asset-dir")
27
+ assetDirs.push(value);
28
+ else
29
+ options[key] = value;
30
+ }
31
+ else if (!args[i].startsWith("-") && !sourceRoot)
32
+ sourceRoot = args[i];
33
+ else
34
+ throw new Error(`Unknown argument: ${args[i]}`);
35
+ }
36
+ const config = options["--config"]
37
+ ? options["--config"].endsWith(".json")
38
+ ? JSON.parse(fs.readFileSync(options["--config"], "utf8"))
39
+ : (await import(pathToFileURL(path.resolve(options["--config"])).href))
40
+ .default
41
+ : {};
42
+ console.log(JSON.stringify(buildSite({
43
+ ...config,
44
+ sourceRoot: sourceRoot ?? config.sourceRoot ?? "docs",
45
+ outDir: options["--out-dir"] ?? config.outDir ?? "site",
46
+ library: options["--library"] ?? config.library,
47
+ links: (options["--links"] ?? config.links),
48
+ hostUrl: options["--host-url"] ?? config.hostUrl,
49
+ assetDirs: assetDirs.length ? assetDirs : config.assetDirs,
50
+ })));
51
+ }
52
+ catch (error) {
53
+ console.error(error);
54
+ process.exitCode = 1;
55
+ }
56
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,SAAS,EAAoB,MAAM,YAAY,CAAA;AAExD,IAAI,CAAC;IACH,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAClC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO;QACrB,MAAM,IAAI,KAAK,CACb,0LAA0L,CAC3L,CAAA;IACH,MAAM,OAAO,GAA2B,EAAE,CAAA;IAC1C,MAAM,SAAS,GAAa,EAAE,CAAA;IAC9B,IAAI,UAA8B,CAAA;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IACE;YACE,WAAW;YACX,UAAU;YACV,WAAW;YACX,SAAS;YACT,YAAY;YACZ,aAAa;SACd,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACnB,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YACnB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAA;YAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CA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,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS;KAC3D,CAAC,CACH,CACF,CAAA;AACH,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;AACtB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { DocumentOptions } from "@cudoment/cudoc/document";
2
+ import { type RenderOptions } from "@cudoment/cudoc/render";
3
+ import { type SiteLinkMode } from "./links.js";
4
+ export type { SiteLinkMode } from "./links.js";
5
+ export type SiteOptions = DocumentOptions & {
6
+ sourceRoot: string;
7
+ outDir: string;
8
+ title?: string;
9
+ navigation?: string[];
10
+ css?: string;
11
+ libraryDir?: string;
12
+ /** Reuse an existing collected host library without recompiling or writing to it. */
13
+ library?: string;
14
+ links?: SiteLinkMode;
15
+ /** Deployment URL, including any site base path. Required for links: "host". */
16
+ hostUrl?: string;
17
+ /** Additional URL-root asset directories, such as a host's static/ or public/. */
18
+ assetDirs?: string[];
19
+ renderOptions?: RenderOptions;
20
+ };
21
+ export declare const siteStyles = "\n:root{color-scheme:light;--ink:#172033;--muted:#526176;--line:#d6dee9;--paper:#fff;--wash:#f4f7fb;--accent:#174ea6;font-family:system-ui,-apple-system,BlinkMacSystemFont,\"Segoe UI\",sans-serif;font-size:16px;line-height:1.65;color:var(--ink);background:var(--paper)}\n*{box-sizing:border-box}body{margin:0}a{color:var(--accent);text-underline-offset:.2em;overflow-wrap:anywhere}a:hover{text-decoration-thickness:2px}:focus-visible{outline:3px solid var(--accent);outline-offset:4px}.skip{position:absolute;left:1rem;top:-5rem;background:white;padding:.7rem;z-index:3}.skip:focus{top:1rem}\nheader{border-bottom:1px solid var(--line);padding:1rem 2rem;font-weight:700}header a{color:inherit;text-decoration:none}.layout{display:grid;grid-template-columns:16rem minmax(0,52rem) 14rem;max-width:90rem;margin:auto;gap:2.5rem;padding:2rem}nav{font-size:.9rem}nav ul{list-style:none;padding:0}nav li{margin:.25rem 0}nav a{display:block;padding:.55rem .65rem;border-radius:.35rem;text-decoration:none}nav a[aria-current=page]{background:#e9f0fc;font-weight:650}nav a:hover{background:var(--wash)}.nav-title{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)}main{min-width:0}h1,h2,h3,h4,h5,h6{line-height:1.3;scroll-margin-top:1rem}h1{font-size:2.25rem;letter-spacing:-.025em}h2{margin-top:2.5rem;padding-top:1rem;border-top:1px solid var(--line)}p,ul,ol{margin:1rem 0}img{max-width:100%;height:auto}pre{background:var(--wash);border:1px solid var(--line);padding:1rem;overflow:auto;border-radius:.4rem}code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:.875em}p code,li code{background:var(--wash);padding:.1em .25em;border-radius:.2em}table{display:block;max-width:100%;overflow:auto;border-collapse:collapse;margin:1.25rem 0}th,td{border:1px solid var(--line);padding:.65rem .8rem;text-align:left;vertical-align:top}th{background:var(--wash)}td p,td ul,td ol{margin:.3rem 0}blockquote{border-left:3px solid var(--line);padding:.1rem 1rem;margin:1.3rem 0;color:var(--muted)}.cudoc-badge{display:inline-block;background:#e9f0fc;color:#174ea6;font-size:.75em;padding:.05em .5em;border-radius:.3em;margin-left:.3em;font-weight:600}.cudoc-callout{border:1px solid var(--line);border-left:4px solid var(--accent);background:var(--wash);padding:.25rem 1rem;margin:1.5rem 0;border-radius:.35rem}.cudoc-callout-title{font-weight:700}.cudoc-callout-warning,.cudoc-callout-caution{border-left-color:#936000;background:#fff8e6}.cudoc-callout-danger{border-left-color:#aa2020}.hljs-keyword,.hljs-selector-tag{color:#7a269e}.hljs-string,.hljs-attr{color:#0a6851}.hljs-comment{color:#526176}.hljs-number,.hljs-literal{color:#8d3900}footer{border-top:1px solid var(--line);margin-top:3rem;padding-top:1rem;color:var(--muted);font-size:.85rem}.toc a{padding:.35rem 0}.toc li[data-depth=\"3\"]{padding-left:1rem}\n@media(max-width:1100px){.layout{grid-template-columns:13rem minmax(0,1fr);gap:2rem}.toc{display:none}}@media(max-width:700px){header{padding:1rem}.layout{display:block;padding:1rem}.sidebar{border-bottom:1px solid var(--line);padding-bottom:1rem}.sidebar ul{display:flex;flex-wrap:wrap;gap:.25rem}h1{font-size:1.8rem}nav a{min-height:44px}main{padding-top:1rem}}@media print{header,.sidebar,.toc,.skip{display:none}.layout{display:block;padding:0}a{color:inherit}pre,table{overflow:visible}.cudoc-callout{break-inside:avoid}}\n";
22
+ export declare function buildSite({ sourceRoot, outDir, title, navigation, css, libraryDir, library: existingLibrary, links, hostUrl, assetDirs, renderOptions, ...options }: SiteOptions): {
23
+ outDir: string;
24
+ documentCount: number;
25
+ libraryDir: string;
26
+ };
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,0BAA0B,CAAA;AAQ7E,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAQ3E,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAC1C,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B,CAAA;AASD,eAAO,MAAM,UAAU,szGAKtB,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,UAAU,EACV,MAAM,EACN,KAAuB,EACvB,UAAU,EACV,GAAG,EACH,UAAmE,EACnE,OAAO,EAAE,eAAe,EACxB,KAAkB,EAClB,OAAO,EACP,SAAc,EACd,aAAa,EACb,GAAG,OAAO,EACX,EAAE,WAAW;;;;EAqMb"}
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fromHtml } from "hast-util-from-html";
4
+ import { toHtml } from "hast-util-to-html";
5
+ import hljs from "highlight.js";
6
+ import { nodeText, visibleHeadingText } from "@cudoment/cudoc/document";
7
+ import { buildDocuments, loadLibrary, } from "@cudoment/cudoc/node/library";
8
+ import { resolveDocumentEmbeds } from "@cudoment/cudoc/node/resolve-embed";
9
+ import { renderDocument } from "@cudoment/cudoc/render";
10
+ import { publishDirectory, safePath, posix, realPath, contained, } from "@cudoment/cudoc/node/storage";
11
+ import { createTargets, deploymentUrl, hostedRoute, rewritePageLinks, externalUrl, } from "./links.js";
12
+ import { preparedDocument } from "./library.js";
13
+ const escape = (value) => value.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[char]);
14
+ export const siteStyles = `
15
+ :root{color-scheme:light;--ink:#172033;--muted:#526176;--line:#d6dee9;--paper:#fff;--wash:#f4f7fb;--accent:#174ea6;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;font-size:16px;line-height:1.65;color:var(--ink);background:var(--paper)}
16
+ *{box-sizing:border-box}body{margin:0}a{color:var(--accent);text-underline-offset:.2em;overflow-wrap:anywhere}a:hover{text-decoration-thickness:2px}:focus-visible{outline:3px solid var(--accent);outline-offset:4px}.skip{position:absolute;left:1rem;top:-5rem;background:white;padding:.7rem;z-index:3}.skip:focus{top:1rem}
17
+ header{border-bottom:1px solid var(--line);padding:1rem 2rem;font-weight:700}header a{color:inherit;text-decoration:none}.layout{display:grid;grid-template-columns:16rem minmax(0,52rem) 14rem;max-width:90rem;margin:auto;gap:2.5rem;padding:2rem}nav{font-size:.9rem}nav ul{list-style:none;padding:0}nav li{margin:.25rem 0}nav a{display:block;padding:.55rem .65rem;border-radius:.35rem;text-decoration:none}nav a[aria-current=page]{background:#e9f0fc;font-weight:650}nav a:hover{background:var(--wash)}.nav-title{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)}main{min-width:0}h1,h2,h3,h4,h5,h6{line-height:1.3;scroll-margin-top:1rem}h1{font-size:2.25rem;letter-spacing:-.025em}h2{margin-top:2.5rem;padding-top:1rem;border-top:1px solid var(--line)}p,ul,ol{margin:1rem 0}img{max-width:100%;height:auto}pre{background:var(--wash);border:1px solid var(--line);padding:1rem;overflow:auto;border-radius:.4rem}code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:.875em}p code,li code{background:var(--wash);padding:.1em .25em;border-radius:.2em}table{display:block;max-width:100%;overflow:auto;border-collapse:collapse;margin:1.25rem 0}th,td{border:1px solid var(--line);padding:.65rem .8rem;text-align:left;vertical-align:top}th{background:var(--wash)}td p,td ul,td ol{margin:.3rem 0}blockquote{border-left:3px solid var(--line);padding:.1rem 1rem;margin:1.3rem 0;color:var(--muted)}.cudoc-badge{display:inline-block;background:#e9f0fc;color:#174ea6;font-size:.75em;padding:.05em .5em;border-radius:.3em;margin-left:.3em;font-weight:600}.cudoc-callout{border:1px solid var(--line);border-left:4px solid var(--accent);background:var(--wash);padding:.25rem 1rem;margin:1.5rem 0;border-radius:.35rem}.cudoc-callout-title{font-weight:700}.cudoc-callout-warning,.cudoc-callout-caution{border-left-color:#936000;background:#fff8e6}.cudoc-callout-danger{border-left-color:#aa2020}.hljs-keyword,.hljs-selector-tag{color:#7a269e}.hljs-string,.hljs-attr{color:#0a6851}.hljs-comment{color:#526176}.hljs-number,.hljs-literal{color:#8d3900}footer{border-top:1px solid var(--line);margin-top:3rem;padding-top:1rem;color:var(--muted);font-size:.85rem}.toc a{padding:.35rem 0}.toc li[data-depth="3"]{padding-left:1rem}
18
+ @media(max-width:1100px){.layout{grid-template-columns:13rem minmax(0,1fr);gap:2rem}.toc{display:none}}@media(max-width:700px){header{padding:1rem}.layout{display:block;padding:1rem}.sidebar{border-bottom:1px solid var(--line);padding-bottom:1rem}.sidebar ul{display:flex;flex-wrap:wrap;gap:.25rem}h1{font-size:1.8rem}nav a{min-height:44px}main{padding-top:1rem}}@media print{header,.sidebar,.toc,.skip{display:none}.layout{display:block;padding:0}a{color:inherit}pre,table{overflow:visible}.cudoc-callout{break-inside:avoid}}
19
+ `;
20
+ export function buildSite({ sourceRoot, outDir, title = "Documentation", navigation, css, libraryDir = path.join(path.dirname(outDir), ".cudoc", "documents"), library: existingLibrary, links = "relative", hostUrl, assetDirs = [], renderOptions, ...options }) {
21
+ const deployment = deploymentUrl(links, hostUrl);
22
+ if (existingLibrary !== undefined &&
23
+ (typeof existingLibrary !== "string" || !existingLibrary))
24
+ throw new Error("cudoc-html: library must be a collected library directory");
25
+ if (!Array.isArray(assetDirs) ||
26
+ assetDirs.some((dir) => typeof dir !== "string" || !dir))
27
+ throw new Error("cudoc-html: assetDirs must contain directory paths");
28
+ libraryDir = existingLibrary ?? libraryDir;
29
+ const output = realPath(outDir);
30
+ for (const input of [sourceRoot, libraryDir, ...assetDirs]) {
31
+ const resolved = realPath(input);
32
+ if (contained(resolved, output) || contained(output, resolved))
33
+ throw new Error("cudoc-html: site output overlaps source, library or asset directory");
34
+ }
35
+ if (existingLibrary && Object.keys(options).length)
36
+ throw new Error("cudoc-html: syntax/compiler options belong to collection when reusing a library");
37
+ const library = existingLibrary
38
+ ? loadLibrary(existingLibrary, undefined, sourceRoot)
39
+ : buildDocuments({
40
+ ...options,
41
+ host: "html",
42
+ sourceRoot,
43
+ outDir: libraryDir,
44
+ });
45
+ const targets = createTargets(library, deployment);
46
+ const ids = library.documents.map((d) => d.id);
47
+ if (!ids.length)
48
+ throw new Error("cudoc-html: no documents found");
49
+ for (const id of navigation ?? [])
50
+ if (!ids.includes(id))
51
+ throw new Error(`cudoc-html: unknown navigation document ${id}`);
52
+ const order = [...new Set([...(navigation ?? []), ...ids])];
53
+ const titles = new Map(library.documents.map((doc) => [
54
+ doc.id,
55
+ String(doc.frontmatter.title ??
56
+ nodeText((doc.tree.children.find((n) => n.type === "heading") ?? {
57
+ type: "text",
58
+ value: doc.id,
59
+ }))),
60
+ ]));
61
+ const documentMap = new Map(library.documents.map((doc) => [doc.id, doc]));
62
+ const outputPath = (id) => `${id}.html`;
63
+ const relativeLink = (from, to) => posix(path.posix.relative(path.posix.dirname(outputPath(from)), to)) ||
64
+ path.posix.basename(to);
65
+ const reservedOutputs = new Set([
66
+ "cudoc.css",
67
+ "index.html",
68
+ ...ids.map((id) => outputPath(id).toLowerCase()),
69
+ ]);
70
+ publishDirectory(sourceRoot, outDir, (staging) => {
71
+ const copied = new Map();
72
+ const copyAsset = (url, doc) => {
73
+ if (/^(?:#|[a-z][\w+.-]*:|\/\/)/i.test(url))
74
+ return url;
75
+ const [, pathname, suffix] = url.match(/^([^?#]*)(.*)$/);
76
+ const decoded = decodeURIComponent(pathname);
77
+ const relative = path.posix.normalize(decoded.startsWith("/")
78
+ ? decoded.slice(1)
79
+ : path.posix.join(path.posix.dirname(doc.sourcePath), decoded));
80
+ const rootPath = targets
81
+ .withoutBase(decoded.startsWith("/") ? decoded : `/${relative}`)
82
+ .replace(/^\//, "");
83
+ const candidates = [
84
+ { root: sourceRoot, relative },
85
+ ...assetDirs.map((root) => ({ root, relative: rootPath })),
86
+ ];
87
+ for (const candidate of candidates) {
88
+ const source = safePath(candidate.root, candidate.relative);
89
+ if (!fs.existsSync(source) || !fs.statSync(source).isFile())
90
+ continue;
91
+ const asset = candidate.relative;
92
+ if (reservedOutputs.has(asset.toLowerCase()))
93
+ throw new Error(`cudoc-html: asset collides with generated output: ${asset}`);
94
+ const previous = copied.get(asset.toLowerCase());
95
+ if (previous && previous !== fs.realpathSync(source))
96
+ throw new Error(`cudoc-html: different assets share output path: ${asset}`);
97
+ const destination = safePath(staging, asset);
98
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
99
+ fs.copyFileSync(source, destination);
100
+ copied.set(asset.toLowerCase(), fs.realpathSync(source));
101
+ return `${relativeLink(doc.id, asset)}${suffix}`;
102
+ }
103
+ throw new Error(`cudoc-html: missing local target ${url} in ${doc.id}; check sourceRoot and assetDirs`);
104
+ };
105
+ const writePage = (page, doc) => {
106
+ const tree = fromHtml(page);
107
+ rewritePageLinks(tree, links, (url) => {
108
+ if (links === "relative" && url.startsWith("#"))
109
+ return url;
110
+ const target = targets.find(url, doc);
111
+ if (links === "host") {
112
+ if (target.document)
113
+ return `${hostedRoute(target.document.route, deployment)}${target.suffix}`;
114
+ if (url.startsWith("/"))
115
+ return hostedRoute(url, deployment);
116
+ return new URL(url, hostedRoute(doc.route, deployment)).href;
117
+ }
118
+ return target.document
119
+ ? `${relativeLink(doc.id, outputPath(target.document.id))}${target.suffix}`
120
+ : copyAsset(url, doc);
121
+ });
122
+ const output = safePath(staging, outputPath(doc.id));
123
+ fs.mkdirSync(path.dirname(output), { recursive: true });
124
+ fs.writeFileSync(output, toHtml(tree));
125
+ };
126
+ fs.writeFileSync(path.join(staging, "cudoc.css"), siteStyles + (css ? `\n${fs.readFileSync(css, "utf8")}` : ""));
127
+ for (const doc of library.documents) {
128
+ const tree = existingLibrary
129
+ ? preparedDocument(doc, libraryDir)
130
+ : resolveDocumentEmbeds(library, doc.id);
131
+ const html = renderDocument(tree, {
132
+ highlight(code, language) {
133
+ const value = language && hljs.getLanguage(language)
134
+ ? hljs.highlight(code, { language }).value
135
+ : escape(code);
136
+ return `<pre><code class="hljs${language ? ` language-${escape(language)}` : ""}">${value}</code></pre>`;
137
+ },
138
+ ...renderOptions,
139
+ });
140
+ const hast = fromHtml(html, { fragment: true });
141
+ const rewrite = (node) => {
142
+ if (node.type === "element") {
143
+ // Hyperlinks are handled on the complete page; keep rendering resources local.
144
+ for (const key of [
145
+ "src",
146
+ ...(node.tagName === "link" ? ["href"] : []),
147
+ ]) {
148
+ const url = node.properties[key];
149
+ if (typeof url === "string" && !externalUrl(url))
150
+ node.properties[key] = copyAsset(url, doc);
151
+ }
152
+ }
153
+ if ("children" in node)
154
+ node.children.forEach(rewrite);
155
+ };
156
+ rewrite(hast);
157
+ const headings = [];
158
+ const collect = (node) => {
159
+ if (node.type === "heading" && node.depth > 1)
160
+ headings.push(node);
161
+ node.children?.forEach(collect);
162
+ };
163
+ collect(tree);
164
+ const nav = order
165
+ .map((id) => `<li><a href="${escape(relativeLink(doc.id, documentMap.get(id).sourcePath))}"${id === doc.id ? ' aria-current="page"' : ""}>${escape(titles.get(id))}</a></li>`)
166
+ .join("");
167
+ const toc = headings
168
+ .map((node) => `<li data-depth="${node.depth}"><a href="#${escape(String(node.data?.hProperties?.id ?? ""))}">${escape(visibleHeadingText(node))}</a></li>`)
169
+ .join("");
170
+ const page = `<!doctype html><html lang="${escape(String(doc.frontmatter.lang ?? "en"))}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escape(titles.get(doc.id))} · ${escape(title)}</title><link rel="stylesheet" href="${escape(relativeLink(doc.id, "cudoc.css"))}"></head><body>${links === "relative" ? '<a class="skip" href="#main-content">Skip to content</a>' : ""}<header><a href="${escape(relativeLink(doc.id, documentMap.get(order[0]).sourcePath))}">${escape(title)}</a></header><div class="layout"><nav class="sidebar" aria-label="Documents"><p class="nav-title">Documents</p><ul>${nav}</ul></nav><main id="main-content">${toHtml(hast)}<footer>${escape(title)}</footer></main><nav class="toc" aria-label="On this page"><p class="nav-title">On this page</p><ul>${toc}</ul></nav></div></body></html>`;
171
+ writePage(page, doc);
172
+ }
173
+ if (!documentMap.has("index")) {
174
+ const index = {
175
+ ...library.documents[0],
176
+ id: "index",
177
+ sourcePath: "index.md",
178
+ route: "/",
179
+ };
180
+ writePage(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escape(title)}</title><link rel="stylesheet" href="cudoc.css"></head><body><header>${escape(title)}</header><main style="max-width:60rem;margin:2rem auto;padding:1rem"><h1>${escape(title)}</h1><nav aria-label="Documents"><ul>${order.map((id) => `<li><a href="${escape(documentMap.get(id).sourcePath)}">${escape(titles.get(id))}</a></li>`).join("")}</ul></nav></main></body></html>`, index);
181
+ }
182
+ });
183
+ return {
184
+ outDir: path.resolve(outDir),
185
+ documentCount: library.documents.length,
186
+ libraryDir: path.resolve(libraryDir),
187
+ };
188
+ }
189
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,IAAI,MAAM,cAAc,CAAA;AAG/B,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACvE,OAAO,EACL,cAAc,EACd,WAAW,GAEZ,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAsB,MAAM,wBAAwB,CAAA;AAC3E,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,SAAS,GACV,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,GAEZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,gB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AC,KAAK,CAAC,4EAA4E,MAAM,CAAC,KAAK,CAAC,wCAAwC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,gBAAgB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,UAAU,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,kCAAkC,EACvgB,KAAK,CACN,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAC5B,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM;QACvC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;KACrC,CAAA;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Root } from "mdast";
2
+ import type { StoredDocument } from "@cudoment/cudoc/node/library";
3
+ /** Reuse native host output, including replacements compiled by asynchronous hosts. */
4
+ export declare function preparedDocument(document: StoredDocument, libraryDir: string): Root;
5
+ //# sourceMappingURL=library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAOlE,uFAAuF;AACvF,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,MAAM,GACjB,IAAI,CA2BN"}
@@ -0,0 +1,25 @@
1
+ import { embedKey, readPreparedEmbeds, } from "@cudoment/cudoc/node/prepare-embeds";
2
+ /** Reuse native host output, including replacements compiled by asynchronous hosts. */
3
+ export function preparedDocument(document, libraryDir) {
4
+ const tree = structuredClone(document.tree);
5
+ let prepared;
6
+ let index = 0;
7
+ const expand = (node) => {
8
+ if (!node.children)
9
+ return;
10
+ node.children = node.children.flatMap((child) => {
11
+ if (child.type === "code" && child.lang === "cudoc-embed") {
12
+ prepared ??= readPreparedEmbeds(libraryDir, document.id, document.source.text);
13
+ const block = prepared.blocks[embedKey(document.id, child.value, ++index)];
14
+ if (!block)
15
+ throw new Error(`cudoc-html: prepared embed missing in ${document.id}; recollect documents`);
16
+ return structuredClone(block.children);
17
+ }
18
+ expand(child);
19
+ return [child];
20
+ });
21
+ };
22
+ expand(tree);
23
+ return tree;
24
+ }
25
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,QAAQ,EACR,kBAAkB,GAEnB,MAAM,qCAAqC,CAAA;AAE5C,uFAAuF;AACvF,MAAM,UAAU,gBAAgB,CAC9B,QAAwB,EACxB,UAAkB;IAElB,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,QAAoC,CAAA;IACxC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,MAAM,MAAM,GAAG,CAAC,IAAkB,EAAE,EAAE;QACpC,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAM;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC1D,QAAQ,KAAK,kBAAkB,CAC7B,UAAU,EACV,QAAQ,CAAC,EAAE,EACX,QAAQ,CAAC,MAAM,CAAC,IAAI,CACrB,CAAA;gBACD,MAAM,KAAK,GACT,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,KAAM,EAAE,EAAE,KAAK,CAAC,CAAC,CAAA;gBAC/D,IAAI,CAAC,KAAK;oBACR,MAAM,IAAI,KAAK,CACb,yCAAyC,QAAQ,CAAC,EAAE,uBAAuB,CAC5E,CAAA;gBACH,OAAO,eAAe,CAAC,KAAK,CAAC,QAAQ,CAA8B,CAAA;YACrE,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,CAAA;YACb,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,MAAM,CAAC,IAA+B,CAAC,CAAA;IACvC,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Root } from "hast";
2
+ import type { Library, StoredDocument } from "@cudoment/cudoc/node/library";
3
+ export type SiteLinkMode = "relative" | "host" | "none";
4
+ export declare const externalUrl: (url: string) => boolean;
5
+ export declare function deploymentUrl(mode: SiteLinkMode, value?: string): URL | undefined;
6
+ /** Document routes are relative to the deployment; already-prefixed routes stay intact. */
7
+ export declare function hostedRoute(route: string, base: URL): string;
8
+ export declare function createTargets(library: Library, base?: URL): {
9
+ withoutBase: (pathname: string) => string;
10
+ find(url: string, from: StoredDocument): {
11
+ document: StoredDocument | undefined;
12
+ suffix: string;
13
+ };
14
+ };
15
+ /** Apply to the complete page, including generated navigation and raw HTML. */
16
+ export declare function rewritePageLinks(tree: Root, mode: SiteLinkMode, rewrite: (url: string) => string): void;
17
+ //# sourceMappingURL=links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,MAAM,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE3E,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;AACvD,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,YACA,CAAA;AAEvC,wBAAgB,aAAa,CAC3B,IAAI,EAAE,YAAY,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,GAAG,GAAG,SAAS,CAwBjB;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,MAAM,CAQ5D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,GAAG;4BAKzB,MAAM;cAQzB,MAAM,QAAQ,cAAc;;;;EA2BzC;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAC/B,IAAI,CA6BN"}
package/dist/links.js ADDED
@@ -0,0 +1,102 @@
1
+ import path from "node:path";
2
+ export const externalUrl = (url) => /^(?:[a-z][\w+.-]*:|\/\/)/i.test(url);
3
+ export function deploymentUrl(mode, value) {
4
+ if (!["relative", "host", "none"].includes(mode))
5
+ throw new Error(`cudoc-html: invalid links mode: ${mode}`);
6
+ if (value === undefined && mode !== "host")
7
+ return undefined;
8
+ let url;
9
+ try {
10
+ url = new URL(value ?? "");
11
+ }
12
+ catch {
13
+ throw new Error("cudoc-html: host links require an absolute HTTP(S) hostUrl");
14
+ }
15
+ if (!["http:", "https:"].includes(url.protocol) ||
16
+ url.username ||
17
+ url.password ||
18
+ url.search ||
19
+ url.hash)
20
+ throw new Error("cudoc-html: hostUrl must be HTTP(S) without credentials, query or fragment");
21
+ url.pathname = url.pathname.replace(/\/?$/, "/");
22
+ return url;
23
+ }
24
+ /** Document routes are relative to the deployment; already-prefixed routes stay intact. */
25
+ export function hostedRoute(route, base) {
26
+ const prefix = base.pathname.replace(/\/$/, "");
27
+ return new URL(prefix && (route === prefix || route.startsWith(`${prefix}/`))
28
+ ? route
29
+ : `${base.pathname}${route.replace(/^\//, "")}`, base).href;
30
+ }
31
+ export function createTargets(library, base) {
32
+ const key = (value) => decodeURIComponent(value).replace(/\/$/, "") || "/";
33
+ const routes = new Map(library.documents.map((doc) => [key(doc.route), doc]));
34
+ const documents = new Map(library.documents.map((doc) => [doc.id, doc]));
35
+ const withoutBase = (pathname) => {
36
+ const prefix = base?.pathname.replace(/\/$/, "");
37
+ return prefix && (pathname === prefix || pathname.startsWith(`${prefix}/`))
38
+ ? pathname.slice(prefix.length) || "/"
39
+ : pathname;
40
+ };
41
+ return {
42
+ withoutBase,
43
+ find(url, from) {
44
+ const [, pathname, suffix] = url.match(/^([^?#]*)(.*)$/);
45
+ if (!pathname)
46
+ return { document: from, suffix };
47
+ const decoded = decodeURIComponent(pathname);
48
+ const sourcePath = path.posix.normalize(decoded.startsWith("/")
49
+ ? decoded.slice(1)
50
+ : path.posix.join(path.posix.dirname(from.sourcePath), decoded));
51
+ const routePath = new URL(url, `https://cudoc.invalid${from.route}`)
52
+ .pathname;
53
+ const route = routes.get(key(pathname.startsWith("/") ? pathname : routePath)) ??
54
+ routes.get(key(withoutBase(pathname.startsWith("/") ? pathname : routePath)));
55
+ const id = sourcePath.replace(/\.(?:mdx?|html)$/i, "").replace(/\/$/, "");
56
+ const bySource = documents.get(id) ?? documents.get(`${id}/index`);
57
+ // Markdown references name source files; extensionless/native URLs name routes.
58
+ return {
59
+ document: /\.mdx?$/i.test(pathname)
60
+ ? (bySource ?? route)
61
+ : (route ?? bySource),
62
+ suffix,
63
+ };
64
+ },
65
+ };
66
+ }
67
+ /** Apply to the complete page, including generated navigation and raw HTML. */
68
+ export function rewritePageLinks(tree, mode, rewrite) {
69
+ const walk = (node) => {
70
+ if (node.type === "element" && ["a", "area"].includes(node.tagName)) {
71
+ if (mode === "none") {
72
+ if (node.tagName === "a")
73
+ node.tagName = "span";
74
+ for (const key of [
75
+ "href",
76
+ "xLinkHref",
77
+ "target",
78
+ "rel",
79
+ "download",
80
+ "ping",
81
+ "hrefLang",
82
+ "referrerPolicy",
83
+ "tabIndex",
84
+ ])
85
+ delete node.properties[key];
86
+ if (node.properties.role === "link")
87
+ delete node.properties.role;
88
+ }
89
+ else {
90
+ for (const key of ["href", "xLinkHref"]) {
91
+ const url = node.properties[key];
92
+ if (typeof url === "string" && !externalUrl(url))
93
+ node.properties[key] = rewrite(url);
94
+ }
95
+ }
96
+ }
97
+ if ("children" in node)
98
+ node.children.forEach(walk);
99
+ };
100
+ walk(tree);
101
+ }
102
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CACzC,2BAA2B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAEvC,MAAM,UAAU,aAAa,CAC3B,IAAkB,EAClB,KAAc;IAEd,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAA;IAC5D,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,SAAS,CAAA;IAC5D,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAA;IACH,CAAC;IACD,IACE,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC3C,GAAG,CAAC,QAAQ;QACZ,GAAG,CAAC,QAAQ;QACZ,GAAG,CAAC,MAAM;QACV,GAAG,CAAC,IAAI;QAER,MAAM,IAAI,KAAK,CACb,4EAA4E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,MAAM;oBAAE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAA;YAClE,CAAC;iBAAM,CAAC;gBACN,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;oBACxC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;oBAChC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;wBAC9C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;gBACvC,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,UAAU,IAAI,IAAI;YAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACrD,CAAC,CAAA;IACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACZ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "cudoc-html",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "author": "cudoment",
7
+ "description": "Build portable HTML documentation sites with cudoc",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc --build"
23
+ },
24
+ "dependencies": {
25
+ "@cudoment/cudoc": "0.2.0",
26
+ "hast-util-from-html": "^2.0.3",
27
+ "hast-util-to-html": "^9.0.5",
28
+ "highlight.js": "^11.12.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "bin": {
34
+ "cudoc-html": "./dist/cli.js"
35
+ },
36
+ "homepage": "https://github.com/cudoment/cudoc/tree/main/packages/cudoc-html#readme",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/cudoment/cudoc.git",
40
+ "directory": "packages/cudoc-html"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }