@dogsbay/format-rst 0.2.0-beta.101
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.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +188 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/plain.d.ts +25 -0
- package/dist/loaders/plain.d.ts.map +1 -0
- package/dist/loaders/plain.js +161 -0
- package/dist/loaders/plain.js.map +1 -0
- package/dist/loaders/sphinx.d.ts +26 -0
- package/dist/loaders/sphinx.d.ts.map +1 -0
- package/dist/loaders/sphinx.js +194 -0
- package/dist/loaders/sphinx.js.map +1 -0
- package/dist/parse.d.ts +19 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +30 -0
- package/dist/parse.js.map +1 -0
- package/dist/sidecar.d.ts +21 -0
- package/dist/sidecar.d.ts.map +1 -0
- package/dist/sidecar.js +141 -0
- package/dist/sidecar.js.map +1 -0
- package/dist/transform.d.ts +19 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +675 -0
- package/dist/transform.js.map +1 -0
- package/package.json +43 -0
- package/python/rst2dogsbay.py +124 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sphinx corpus loader.
|
|
3
|
+
*
|
|
4
|
+
* Detects a Sphinx project (`conf.py`), runs `sphinx-build -b xml` once for
|
|
5
|
+
* the whole project (resolving toctree, cross-refs, directives, autodoc),
|
|
6
|
+
* then enumerates the emitted per-doc XML and extracts nav from the master
|
|
7
|
+
* doc's toctree. The transform of each XML → Dogsbay-MD happens in the CLI
|
|
8
|
+
* layer (which reads the files); this loader owns discovery + nav.
|
|
9
|
+
*
|
|
10
|
+
* See plans/format-rst.md Phase 2.
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
13
|
+
import { join, relative } from "node:path";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { parseDocument } from "htmlparser2";
|
|
16
|
+
import { sphinxBuildXml } from "../sidecar.js";
|
|
17
|
+
// ── local dom guards (never instanceof — see transform.ts) ──────────────────
|
|
18
|
+
function isTag(n) {
|
|
19
|
+
return n.type === "tag" || n.type === "script" || n.type === "style";
|
|
20
|
+
}
|
|
21
|
+
function els(n) {
|
|
22
|
+
return n.children.filter(isTag);
|
|
23
|
+
}
|
|
24
|
+
function text(n) {
|
|
25
|
+
let s = "";
|
|
26
|
+
for (const c of n.children) {
|
|
27
|
+
if (c.type === "text")
|
|
28
|
+
s += c.data ?? "";
|
|
29
|
+
else if (isTag(c))
|
|
30
|
+
s += text(c);
|
|
31
|
+
}
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
function firstDesc(n, tag) {
|
|
35
|
+
for (const c of els(n)) {
|
|
36
|
+
if (c.tagName === tag)
|
|
37
|
+
return c;
|
|
38
|
+
const d = firstDesc(c, tag);
|
|
39
|
+
if (d)
|
|
40
|
+
return d;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/** Find the Sphinx source dir (the dir with conf.py) at or below `dir`. */
|
|
45
|
+
export function findSphinxSrc(dir) {
|
|
46
|
+
if (existsSync(join(dir, "conf.py")))
|
|
47
|
+
return dir;
|
|
48
|
+
// Common layouts: docs/, doc/, source/, docs/source/.
|
|
49
|
+
for (const cand of ["docs", "doc", "source", join("docs", "source"), join("doc", "source")]) {
|
|
50
|
+
const p = join(dir, cand);
|
|
51
|
+
if (existsSync(join(p, "conf.py")))
|
|
52
|
+
return p;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/** Read `master_doc`/`root_doc` from conf.py (best-effort regex). */
|
|
57
|
+
function readRootDoc(srcDir) {
|
|
58
|
+
try {
|
|
59
|
+
const conf = readFileSync(join(srcDir, "conf.py"), "utf-8");
|
|
60
|
+
const m = conf.match(/^\s*(?:master_doc|root_doc)\s*=\s*["']([^"']+)["']/m);
|
|
61
|
+
if (m)
|
|
62
|
+
return m[1];
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
/* ignore */
|
|
66
|
+
}
|
|
67
|
+
return "index";
|
|
68
|
+
}
|
|
69
|
+
/** Enumerate every `.xml` under outDir as a doc (slug = path sans .xml). */
|
|
70
|
+
function enumerateDocs(outDir) {
|
|
71
|
+
const docs = [];
|
|
72
|
+
const walk = (dir) => {
|
|
73
|
+
for (const name of readdirSync(dir)) {
|
|
74
|
+
const full = join(dir, name);
|
|
75
|
+
if (statSync(full).isDirectory())
|
|
76
|
+
walk(full);
|
|
77
|
+
else if (name.endsWith(".xml")) {
|
|
78
|
+
const slug = relative(outDir, full).replace(/\\/g, "/").replace(/\.xml$/, "");
|
|
79
|
+
docs.push({ slug, xmlPath: full });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
walk(outDir);
|
|
84
|
+
return docs;
|
|
85
|
+
}
|
|
86
|
+
/** Resolve a toctree entry's refuri (relative to `docDir`) to an absolute
|
|
87
|
+
* docname slug. Anchor-only / external refs return "". */
|
|
88
|
+
function resolveDocSlug(refuri, docDir) {
|
|
89
|
+
if (!refuri || refuri.startsWith("#") || /^[a-z][a-z0-9+.-]*:/i.test(refuri))
|
|
90
|
+
return "";
|
|
91
|
+
const hash = refuri.indexOf("#");
|
|
92
|
+
const path = (hash === -1 ? refuri : refuri.slice(0, hash)).replace(/\.html$/i, "");
|
|
93
|
+
if (!path)
|
|
94
|
+
return "";
|
|
95
|
+
const segs = path.startsWith("/") ? [] : docDir ? docDir.split("/") : [];
|
|
96
|
+
for (const part of path.replace(/^\//, "").split("/")) {
|
|
97
|
+
if (part === "" || part === ".")
|
|
98
|
+
continue;
|
|
99
|
+
if (part === "..")
|
|
100
|
+
segs.pop();
|
|
101
|
+
else
|
|
102
|
+
segs.push(part);
|
|
103
|
+
}
|
|
104
|
+
return segs.join("/");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build the full nav by following toctrees ACROSS documents. Each toctree
|
|
108
|
+
* entry points at a child doc; we recurse into that doc's own toctrees for
|
|
109
|
+
* deeper levels (the master doc alone gives only the top level). A visited
|
|
110
|
+
* set breaks cycles. Section-anchor sub-entries (the maxdepth expansion
|
|
111
|
+
* within a page) are skipped — those are on-page TOC, not sidebar nav; the
|
|
112
|
+
* sidebar mirrors the document hierarchy.
|
|
113
|
+
*/
|
|
114
|
+
function buildSphinxNav(rootDoc, docMap, hrefPrefix) {
|
|
115
|
+
const visited = new Set();
|
|
116
|
+
const navForDoc = (docSlug) => {
|
|
117
|
+
if (visited.has(docSlug))
|
|
118
|
+
return [];
|
|
119
|
+
visited.add(docSlug);
|
|
120
|
+
const xmlPath = docMap.get(docSlug);
|
|
121
|
+
if (!xmlPath)
|
|
122
|
+
return [];
|
|
123
|
+
let xml;
|
|
124
|
+
try {
|
|
125
|
+
xml = readFileSync(xmlPath, "utf-8");
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
const parsed = parseDocument(xml, { xmlMode: true });
|
|
131
|
+
const root = parsed.children.find((c) => isTag(c) && c.tagName === "document");
|
|
132
|
+
if (!root)
|
|
133
|
+
return [];
|
|
134
|
+
const docDir = docSlug.includes("/") ? docSlug.slice(0, docSlug.lastIndexOf("/")) : "";
|
|
135
|
+
const out = [];
|
|
136
|
+
const walk = (el) => {
|
|
137
|
+
for (const child of els(el)) {
|
|
138
|
+
if (child.tagName === "compound" && (child.attribs?.classes ?? "").includes("toctree-wrapper")) {
|
|
139
|
+
for (const cp of els(child).filter((c) => c.tagName === "compact_paragraph")) {
|
|
140
|
+
const captionEl = els(cp).find((c) => c.tagName === "title");
|
|
141
|
+
const list = els(cp).find((c) => c.tagName === "bullet_list");
|
|
142
|
+
const entries = [];
|
|
143
|
+
if (list) {
|
|
144
|
+
for (const li of els(list).filter((c) => c.tagName === "list_item")) {
|
|
145
|
+
const ref = firstDesc(li, "reference");
|
|
146
|
+
if (!ref)
|
|
147
|
+
continue;
|
|
148
|
+
const label = text(ref).trim();
|
|
149
|
+
const childSlug = resolveDocSlug(ref.attribs?.refuri ?? "", docDir);
|
|
150
|
+
const item = childSlug
|
|
151
|
+
? { label, href: `${hrefPrefix}/${childSlug}`.replace(/\/+/g, "/") }
|
|
152
|
+
: { label };
|
|
153
|
+
if (childSlug) {
|
|
154
|
+
const kids = navForDoc(childSlug); // recurse into the child doc
|
|
155
|
+
if (kids.length)
|
|
156
|
+
item.children = kids;
|
|
157
|
+
}
|
|
158
|
+
entries.push(item);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (captionEl)
|
|
162
|
+
out.push({ label: text(captionEl).trim(), children: entries });
|
|
163
|
+
else
|
|
164
|
+
out.push(...entries);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
walk(child);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
walk(root);
|
|
173
|
+
return out;
|
|
174
|
+
};
|
|
175
|
+
return navForDoc(rootDoc);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Load a Sphinx project: build to XML, enumerate docs, extract nav.
|
|
179
|
+
* `outDir` defaults to a temp dir. Throws (via the sidecar) when Python /
|
|
180
|
+
* Sphinx is unavailable or the build fails.
|
|
181
|
+
*/
|
|
182
|
+
export function loadSphinx(sourceDir, hrefPrefix = "") {
|
|
183
|
+
const srcDir = findSphinxSrc(sourceDir);
|
|
184
|
+
if (!srcDir)
|
|
185
|
+
throw new Error(`No Sphinx conf.py found under ${sourceDir}`);
|
|
186
|
+
const outDir = mkdtempSync(join(tmpdir(), "dogsbay-sphinx-xml-"));
|
|
187
|
+
sphinxBuildXml(srcDir, outDir);
|
|
188
|
+
const docs = enumerateDocs(outDir);
|
|
189
|
+
const rootDoc = readRootDoc(srcDir);
|
|
190
|
+
const docMap = new Map(docs.map((d) => [d.slug, d.xmlPath]));
|
|
191
|
+
const nav = docMap.has(rootDoc) ? buildSphinxNav(rootDoc, docMap, hrefPrefix) : [];
|
|
192
|
+
return { srcDir, outDir, docs, nav, rootDoc };
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=sphinx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sphinx.js","sourceRoot":"","sources":["../../src/loaders/sphinx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAoB/C,+EAA+E;AAC/E,SAAS,KAAK,CAAC,CAAU;IACvB,OAAO,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;AACvE,CAAC;AACD,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AACD,SAAS,IAAI,CAAC,CAAU;IACtB,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;YAAE,CAAC,IAAK,CAAuB,CAAC,IAAI,IAAI,EAAE,CAAC;aAC3D,I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Node } from "@dogsbay/types";
|
|
2
|
+
import { type RstLedgerEntry } from "./transform.js";
|
|
3
|
+
export interface ParseRstResult {
|
|
4
|
+
tree: TreeNode[];
|
|
5
|
+
title?: string;
|
|
6
|
+
/** Translated Dogsbay-MD body (no frontmatter) — for migrate to disk. */
|
|
7
|
+
markdown: string;
|
|
8
|
+
ledger: RstLedgerEntry[];
|
|
9
|
+
}
|
|
10
|
+
export declare function parseRstFile(filePath: string, hrefPrefix?: string): ParseRstResult;
|
|
11
|
+
/**
|
|
12
|
+
* Transform an already-obtained docutils XML string (no sidecar spawn).
|
|
13
|
+
* `docPath` is the doc's root-relative slug (Sphinx mode) — enables
|
|
14
|
+
* cross-ref (`:doc:`/`:ref:`) resolution to root-relative links.
|
|
15
|
+
* `hrefPrefix` (site basePath) is applied to those resolved links so they
|
|
16
|
+
* match the nav's hrefs on subpath deploys.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseRstXml(xml: string, docPath?: string, hrefPrefix?: string): ParseRstResult;
|
|
19
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAGlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAI9F"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.rst` file → { tree, title, markdown, ledger }.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: sidecar (docutils/Sphinx → XML) → transform (XML AST →
|
|
5
|
+
* Dogsbay-MD) → dogsbayMdToTree (canonical parser → TreeNode). Mirrors
|
|
6
|
+
* format-gitbook's "translate to Dogsbay-MD, then reuse the parser" shape.
|
|
7
|
+
*
|
|
8
|
+
* `markdown` is what `migrate-rst` writes to disk; `tree` feeds the
|
|
9
|
+
* runtime path.
|
|
10
|
+
*/
|
|
11
|
+
import { dogsbayMdToTree } from "@dogsbay/format-dogsbay-md";
|
|
12
|
+
import { rstFileToXml } from "./sidecar.js";
|
|
13
|
+
import { docutilsXmlToDogsbayMd } from "./transform.js";
|
|
14
|
+
export function parseRstFile(filePath, hrefPrefix) {
|
|
15
|
+
const xml = rstFileToXml(filePath, "plain");
|
|
16
|
+
return parseRstXml(xml, undefined, hrefPrefix);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Transform an already-obtained docutils XML string (no sidecar spawn).
|
|
20
|
+
* `docPath` is the doc's root-relative slug (Sphinx mode) — enables
|
|
21
|
+
* cross-ref (`:doc:`/`:ref:`) resolution to root-relative links.
|
|
22
|
+
* `hrefPrefix` (site basePath) is applied to those resolved links so they
|
|
23
|
+
* match the nav's hrefs on subpath deploys.
|
|
24
|
+
*/
|
|
25
|
+
export function parseRstXml(xml, docPath, hrefPrefix) {
|
|
26
|
+
const { markdown, title, ledger } = docutilsXmlToDogsbayMd(xml, { docPath, hrefPrefix });
|
|
27
|
+
const { tree } = dogsbayMdToTree(markdown);
|
|
28
|
+
return { tree, title, markdown, ledger };
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAuB,MAAM,gBAAgB,CAAC;AAU7E,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,UAAmB;IAChE,MAAM,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,OAAgB,EAAE,UAAmB;IAC5E,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IACzF,MAAM,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class RstSidecarError extends Error {
|
|
2
|
+
}
|
|
3
|
+
/**
|
|
4
|
+
* Find a Python interpreter that has docutils, or null. Result is cached
|
|
5
|
+
* for the process (probing spawns a subprocess). Honours DOGSBAY_PYTHON.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findPython(): string | null;
|
|
8
|
+
/** Human-actionable message when no docutils-capable Python is found. */
|
|
9
|
+
export declare function missingPythonMessage(): string;
|
|
10
|
+
export declare function rstFileToXml(filePath: string, mode?: "plain" | "sphinx"): string;
|
|
11
|
+
/** True when a docutils-capable Python is available. */
|
|
12
|
+
export declare function sidecarAvailable(): boolean;
|
|
13
|
+
/** True when the found Python also has Sphinx (needed for Sphinx mode). */
|
|
14
|
+
export declare function sphinxAvailable(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Run `sphinx-build -b xml <srcDir> <outDir>` — a whole-project build that
|
|
17
|
+
* resolves toctree, cross-references, Sphinx directives, and autodoc into
|
|
18
|
+
* per-doc docutils XML files under outDir. Throws on failure.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sphinxBuildXml(srcDir: string, outDir: string): void;
|
|
21
|
+
//# sourceMappingURL=sidecar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar.d.ts","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAmBA,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAY7C;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAuB1C;AAED,yEAAyE;AACzE,wBAAgB,oBAAoB,IAAI,MAAM,CAM7C;AAYD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,GAAG,QAAkB,GAAG,MAAM,CAczF;AAED,wDAAwD;AACxD,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,IAAI,OAAO,CAazC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAyBnE"}
|
package/dist/sidecar.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python sidecar driver — spawn docutils (via `python/rst2dogsbay.py`) to
|
|
3
|
+
* parse a `.rst` file into docutils XML.
|
|
4
|
+
*
|
|
5
|
+
* rST has no reliable JS parser (see plans/format-rst.md); docutils is the
|
|
6
|
+
* reference implementation. We shell out to it — the same Python-subprocess
|
|
7
|
+
* pattern @dogsbay/autodoc-python already uses — and hand the resulting XML
|
|
8
|
+
* AST to the transformer. Python + docutils are a documented migrate-time
|
|
9
|
+
* requirement; a missing interpreter fails with a clear, actionable error.
|
|
10
|
+
*/
|
|
11
|
+
import { execFileSync } from "node:child_process";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
// dist/sidecar.js → package root → python/rst2dogsbay.py
|
|
17
|
+
const SCRIPT = join(HERE, "..", "python", "rst2dogsbay.py");
|
|
18
|
+
export class RstSidecarError extends Error {
|
|
19
|
+
}
|
|
20
|
+
/** Candidate interpreters, in priority order. `DOGSBAY_PYTHON` wins. */
|
|
21
|
+
function candidatePythons() {
|
|
22
|
+
const out = [];
|
|
23
|
+
if (process.env.DOGSBAY_PYTHON)
|
|
24
|
+
out.push(process.env.DOGSBAY_PYTHON);
|
|
25
|
+
out.push("python3", "python");
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
let cachedPython;
|
|
29
|
+
/**
|
|
30
|
+
* Find a Python interpreter that has docutils, or null. Result is cached
|
|
31
|
+
* for the process (probing spawns a subprocess). Honours DOGSBAY_PYTHON.
|
|
32
|
+
*/
|
|
33
|
+
export function findPython() {
|
|
34
|
+
if (cachedPython !== undefined)
|
|
35
|
+
return cachedPython;
|
|
36
|
+
if (!existsSync(SCRIPT)) {
|
|
37
|
+
// Package mis-packaged (python/ not shipped) — surface loudly.
|
|
38
|
+
throw new RstSidecarError(`rst2dogsbay.py not found at ${SCRIPT}`);
|
|
39
|
+
}
|
|
40
|
+
for (const py of candidatePythons()) {
|
|
41
|
+
try {
|
|
42
|
+
const out = execFileSync(py, [SCRIPT, "--check"], {
|
|
43
|
+
encoding: "utf-8",
|
|
44
|
+
timeout: 10_000,
|
|
45
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
46
|
+
});
|
|
47
|
+
if (out.startsWith("ok ")) {
|
|
48
|
+
cachedPython = py;
|
|
49
|
+
return py;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// interpreter missing or docutils absent — try the next candidate
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
cachedPython = null;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/** Human-actionable message when no docutils-capable Python is found. */
|
|
60
|
+
export function missingPythonMessage() {
|
|
61
|
+
return ("reStructuredText import needs Python 3 with docutils, which was not found.\n" +
|
|
62
|
+
" Install it: python3 -m pip install docutils (add 'sphinx' for Sphinx projects)\n" +
|
|
63
|
+
" Or point Dogsbay at a specific interpreter: DOGSBAY_PYTHON=/path/to/python\n");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parse a `.rst` file to docutils XML. Throws RstSidecarError when no
|
|
67
|
+
* docutils-capable Python is available (caller decides fail vs skip), or
|
|
68
|
+
* when the sidecar itself errors on that file.
|
|
69
|
+
*/
|
|
70
|
+
/** Per-file docutils parse timeout (ms) — a hung parse must not wedge a run. */
|
|
71
|
+
const FILE_TIMEOUT_MS = 60_000;
|
|
72
|
+
/** Whole-project Sphinx build timeout (ms) — generous for large corpora. */
|
|
73
|
+
const BUILD_TIMEOUT_MS = 15 * 60_000;
|
|
74
|
+
export function rstFileToXml(filePath, mode = "plain") {
|
|
75
|
+
const py = findPython();
|
|
76
|
+
if (!py)
|
|
77
|
+
throw new RstSidecarError(missingPythonMessage());
|
|
78
|
+
try {
|
|
79
|
+
return execFileSync(py, [SCRIPT, "--mode", mode, filePath], {
|
|
80
|
+
encoding: "utf-8",
|
|
81
|
+
maxBuffer: 64 * 1024 * 1024, // large docs (numpy pages) exceed the 1MB default
|
|
82
|
+
timeout: FILE_TIMEOUT_MS,
|
|
83
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
88
|
+
throw new RstSidecarError(`docutils failed on ${filePath}: ${msg}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** True when a docutils-capable Python is available. */
|
|
92
|
+
export function sidecarAvailable() {
|
|
93
|
+
return findPython() !== null;
|
|
94
|
+
}
|
|
95
|
+
/** True when the found Python also has Sphinx (needed for Sphinx mode). */
|
|
96
|
+
export function sphinxAvailable() {
|
|
97
|
+
const py = findPython();
|
|
98
|
+
if (!py)
|
|
99
|
+
return false;
|
|
100
|
+
try {
|
|
101
|
+
const out = execFileSync(py, [SCRIPT, "--check-sphinx"], {
|
|
102
|
+
encoding: "utf-8",
|
|
103
|
+
timeout: 10_000,
|
|
104
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
105
|
+
});
|
|
106
|
+
return out.startsWith("ok ");
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Run `sphinx-build -b xml <srcDir> <outDir>` — a whole-project build that
|
|
114
|
+
* resolves toctree, cross-references, Sphinx directives, and autodoc into
|
|
115
|
+
* per-doc docutils XML files under outDir. Throws on failure.
|
|
116
|
+
*/
|
|
117
|
+
export function sphinxBuildXml(srcDir, outDir) {
|
|
118
|
+
const py = findPython();
|
|
119
|
+
if (!py)
|
|
120
|
+
throw new RstSidecarError(missingPythonMessage());
|
|
121
|
+
// SECURITY: sphinx-build EXECUTES the project's conf.py and, for autodoc,
|
|
122
|
+
// IMPORTS its Python modules — arbitrary code from the source repo runs on
|
|
123
|
+
// this machine (inherent to Sphinx, same as running the project's own
|
|
124
|
+
// build). Warn so a user migrating an untrusted repo knows.
|
|
125
|
+
console.warn(`rst: running the project's Sphinx build (executes ${srcDir}/conf.py and imports its modules).\n` +
|
|
126
|
+
" Only migrate repositories you trust. Use --loader plain to skip Sphinx and avoid executing project code.");
|
|
127
|
+
try {
|
|
128
|
+
execFileSync(py, [SCRIPT, "--sphinx-build", srcDir, outDir], {
|
|
129
|
+
encoding: "utf-8",
|
|
130
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
131
|
+
timeout: BUILD_TIMEOUT_MS,
|
|
132
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
137
|
+
throw new RstSidecarError(`sphinx-build failed for ${srcDir}: ${msg}\n` +
|
|
138
|
+
"The project's conf.py may reference extensions/deps not installed in this Python env.");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=sidecar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar.js","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrD,yDAAyD;AACzD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AAE5D,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C,wEAAwE;AACxE,SAAS,gBAAgB;IACvB,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc;QAAE,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACrE,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC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AU,cAAc,CAAC,MAAc,EAAE,MAAc;IAC3D,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,eAAe,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC3D,0EAA0E;IAC1E,2EAA2E;IAC3E,sEAAsE;IACtE,4DAA4D;IAC5D,OAAO,CAAC,IAAI,CACV,qDAAqD,MAAM,sCAAsC;QAC/F,4GAA4G,CAC/G,CAAC;IACF,IAAI,CAAC;QACH,YAAY,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;YAC3D,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;YAC3B,OAAO,EAAE,gBAAgB;YACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,MAAM,IAAI,eAAe,CACvB,2BAA2B,MAAM,KAAK,GAAG,IAAI;YAC3C,uFAAuF,CAC1F,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface RstLedgerEntry {
|
|
2
|
+
construct: string;
|
|
3
|
+
note: string;
|
|
4
|
+
}
|
|
5
|
+
export interface TransformResult {
|
|
6
|
+
markdown: string;
|
|
7
|
+
/** Document title from the root `<document title="…">`, if any. */
|
|
8
|
+
title?: string;
|
|
9
|
+
ledger: RstLedgerEntry[];
|
|
10
|
+
}
|
|
11
|
+
export interface TransformOptions {
|
|
12
|
+
/** Docroot-relative slug of this doc (Sphinx mode). Enables cross-ref
|
|
13
|
+
* resolution: `:doc:` refuris are relative to the current doc. */
|
|
14
|
+
docPath?: string;
|
|
15
|
+
/** URL prefix (site basePath) for resolved cross-doc links. */
|
|
16
|
+
hrefPrefix?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function docutilsXmlToDogsbayMd(xml: string, opts?: TransformOptions): TransformResult;
|
|
19
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAwCA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AA2BD,MAAM,WAAW,gBAAgB;IAC/B;uEACmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,eAAe,CA6BhG"}
|