@dogsbay/format-myst 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.
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Explicit MyST tables of contents:
3
+ * - `_toc.yml` — Jupyter Book (`format: jb-book`, root/parts/chapters/sections)
4
+ * - `myst.yml` — mystmd project config (`project.toc`, file/title/children)
5
+ *
6
+ * Both resolve to `NavItem[]`. Doc references (extensionless or `.md`) are
7
+ * turned into slugs + hrefs via the caller-supplied `slugToHref`.
8
+ */
9
+ import { parse as parseYaml } from "yaml";
10
+ /** Normalize a MyST doc reference to a root-relative slug. */
11
+ export function refToSlug(ref) {
12
+ let p = String(ref).replace(/\\/g, "/").trim();
13
+ p = p.replace(/\.(md|ipynb|rst|myst)$/i, "");
14
+ p = p.replace(/^\.\//, "").replace(/^\//, "");
15
+ if (p === "README" || p === "index")
16
+ return "index";
17
+ p = p.replace(/\/(README|index)$/i, "/index");
18
+ return p;
19
+ }
20
+ function prettify(slug) {
21
+ const base = slug.slice(slug.lastIndexOf("/") + 1);
22
+ return base
23
+ .split(/[-_]/)
24
+ .filter(Boolean)
25
+ .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
26
+ .join(" ");
27
+ }
28
+ /**
29
+ * Parse a Jupyter Book `_toc.yml`. Returns null when the YAML isn't a
30
+ * jb-book TOC (so the caller can fall back to another nav source).
31
+ */
32
+ export function parseJupyterToc(yamlText, titles, slugToHref) {
33
+ let doc;
34
+ try {
35
+ doc = parseYaml(yamlText);
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ if (!doc || typeof doc !== "object")
41
+ return null;
42
+ const d = doc;
43
+ if (typeof d.root !== "string")
44
+ return null;
45
+ const slugs = [];
46
+ const label = (slug) => titles.get(slug) ?? prettify(slug);
47
+ const leaf = (ref) => {
48
+ const slug = refToSlug(ref);
49
+ slugs.push(slug);
50
+ return { label: label(slug), href: slugToHref(slug) };
51
+ };
52
+ // A "chapter"/"section" entry: { file, sections?: [...], title? }.
53
+ const entryToNav = (raw) => {
54
+ if (!raw || typeof raw !== "object")
55
+ return null;
56
+ const e = raw;
57
+ if (typeof e.file !== "string" && typeof e.url !== "string" && typeof e.glob !== "string") {
58
+ return null;
59
+ }
60
+ if (typeof e.url === "string") {
61
+ return { label: typeof e.title === "string" ? e.title : e.url, href: e.url };
62
+ }
63
+ if (typeof e.glob === "string")
64
+ return null; // globs need a filesystem walk; caller handles orphans
65
+ const slug = refToSlug(e.file);
66
+ slugs.push(slug);
67
+ const node = {
68
+ label: typeof e.title === "string" ? e.title : label(slug),
69
+ href: slugToHref(slug),
70
+ };
71
+ const subs = (e.sections ?? e.chapters);
72
+ if (Array.isArray(subs)) {
73
+ const children = subs.map(entryToNav).filter((n) => n !== null);
74
+ if (children.length)
75
+ node.children = children;
76
+ }
77
+ return node;
78
+ };
79
+ const nav = [];
80
+ // Root is the landing page — not usually a nav entry itself, but record it.
81
+ slugs.push(refToSlug(d.root));
82
+ if (Array.isArray(d.parts)) {
83
+ for (const part of d.parts) {
84
+ if (!part || typeof part !== "object")
85
+ continue;
86
+ const p = part;
87
+ const caption = typeof p.caption === "string" ? p.caption : "Section";
88
+ const chapters = Array.isArray(p.chapters) ? p.chapters : [];
89
+ const children = chapters.map(entryToNav).filter((n) => n !== null);
90
+ nav.push({ label: caption, children });
91
+ }
92
+ }
93
+ else if (Array.isArray(d.chapters)) {
94
+ for (const ch of d.chapters) {
95
+ const n = entryToNav(ch);
96
+ if (n)
97
+ nav.push(n);
98
+ }
99
+ }
100
+ return { nav, slugs };
101
+ }
102
+ /**
103
+ * Parse a mystmd `myst.yml` `project.toc`. Returns null when there's no
104
+ * usable `project.toc`.
105
+ */
106
+ export function parseMystYmlToc(yamlText, titles, slugToHref) {
107
+ let doc;
108
+ try {
109
+ doc = parseYaml(yamlText);
110
+ }
111
+ catch {
112
+ return null;
113
+ }
114
+ const project = doc?.project;
115
+ const toc = project?.toc;
116
+ if (!Array.isArray(toc))
117
+ return null;
118
+ const slugs = [];
119
+ const label = (slug) => titles.get(slug) ?? prettify(slug);
120
+ const entryToNav = (raw) => {
121
+ if (!raw || typeof raw !== "object")
122
+ return null;
123
+ const e = raw;
124
+ if (typeof e.file === "string") {
125
+ const slug = refToSlug(e.file);
126
+ slugs.push(slug);
127
+ const node = {
128
+ label: typeof e.title === "string" ? e.title : label(slug),
129
+ href: slugToHref(slug),
130
+ };
131
+ if (Array.isArray(e.children)) {
132
+ const kids = e.children.map(entryToNav).filter((n) => n !== null);
133
+ if (kids.length)
134
+ node.children = kids;
135
+ }
136
+ return node;
137
+ }
138
+ if (typeof e.url === "string") {
139
+ return { label: typeof e.title === "string" ? e.title : e.url, href: e.url };
140
+ }
141
+ if (typeof e.title === "string") {
142
+ // A titled group with children but no file of its own.
143
+ const node = { label: e.title, children: [] };
144
+ if (Array.isArray(e.children)) {
145
+ node.children = e.children.map(entryToNav).filter((n) => n !== null);
146
+ }
147
+ return node;
148
+ }
149
+ return null;
150
+ };
151
+ const nav = toc.map(entryToNav).filter((n) => n !== null);
152
+ return { nav, slugs };
153
+ }
154
+ //# sourceMappingURL=toc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc.js","sourceRoot":"","sources":["../../src/loaders/toc.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAG1C,8DAA8D;AAC9D,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE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AE,CAAC;gBAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;YACrF,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IACxE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { TreeNode } from "@dogsbay/types";
2
+ import { type TranslateLedgerEntry } from "./translate.js";
3
+ export interface ParseMystResult {
4
+ tree: TreeNode[];
5
+ frontmatter: Record<string, unknown>;
6
+ /** Frontmatter + translated body — the editable Dogsbay-MD for migrate. */
7
+ markdown: string;
8
+ /** Translated body only (no frontmatter). */
9
+ body: string;
10
+ ledger: TranslateLedgerEntry[];
11
+ /** In-body `{toctree}` references, in document order. */
12
+ toctree: string[];
13
+ }
14
+ export declare function parseMyst(src: string): ParseMystResult;
15
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,yDAAyD;IACzD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAID,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAmBtD"}
package/dist/parse.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * MyST page → { tree, frontmatter, markdown, body, ledger, toctree }.
3
+ *
4
+ * Pipeline (mirrors format-gitbook):
5
+ * 1. Split YAML frontmatter off the body so the body transform can't
6
+ * disturb it.
7
+ * 2. Translate the MyST body → Dogsbay-MD text (`mystToDogsbayMd`).
8
+ * 3. Parse the translated Dogsbay-MD with the canonical `dogsbayMdToTree`
9
+ * — MyST is a near-superset of CommonMark, so once the directives /
10
+ * roles / targets are rewritten, its own parser defines correctness
11
+ * and yields the TreeNode with zero new node types.
12
+ *
13
+ * `markdown` (frontmatter + translated body) is what `migrate-myst` writes
14
+ * to disk. `toctree` carries any in-body `{toctree}` entries so the loader
15
+ * can build nav.
16
+ */
17
+ import { dogsbayMdToTree } from "@dogsbay/format-dogsbay-md";
18
+ import { mystToDogsbayMd } from "./translate.js";
19
+ const FRONTMATTER_RE = /^---\n([\s\S]*?)\n---\n?/;
20
+ export function parseMyst(src) {
21
+ const normalized = src.replace(/\r\n?/g, "\n");
22
+ const fmMatch = normalized.match(FRONTMATTER_RE);
23
+ const fmBlock = fmMatch ? fmMatch[0] : "";
24
+ const body = fmMatch ? normalized.slice(fmMatch[0].length) : normalized;
25
+ const { markdown: translatedBody, ledger, toctree } = mystToDogsbayMd(body);
26
+ const markdown = fmBlock ? `${fmBlock.replace(/\n?$/, "\n")}\n${translatedBody}` : translatedBody;
27
+ const { tree, frontmatter } = dogsbayMdToTree(markdown);
28
+ return {
29
+ tree,
30
+ frontmatter: frontmatter ?? {},
31
+ markdown,
32
+ body: translatedBody,
33
+ ledger,
34
+ toctree,
35
+ };
36
+ }
37
+ //# sourceMappingURL=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
+ *
4
+ * MyST (Markedly Structured Text) is CommonMark + Sphinx-style
5
+ * **directives**, **roles**, and **targets**. Dogsbay-MD is CommonMark +
6
+ * `:::` block directives + `{attrs}`. So — exactly like the GitBook and
7
+ * AsciiDoc pipelines — translation is largely a delimiter rewrite: prose,
8
+ * lists, tables, and normal fenced code pass through untouched; only the
9
+ * MyST-specific constructs are rewritten, after which the canonical
10
+ * `dogsbayMdToTree` parser is the definition of correctness (zero new
11
+ * TreeNode types).
12
+ *
13
+ * Three MyST construct classes:
14
+ * - **Directives** — a fenced block, either ```` ```{name} ```` (backtick)
15
+ * or `:::{name}` (colon fence). An optional argument follows the name on
16
+ * the opener line; `:key: value` option lines may follow; then a blank
17
+ * line and the body. These map to `:::` block directives (callouts,
18
+ * tabs, grid, details, figure, math, code) and can NEST — emitted with
19
+ * DEPTH-AWARE fence lengths (outer gets more colons), mirroring
20
+ * format-dogsbay-md's serializer and format-gitbook's translator.
21
+ * - **Roles** — inline ``{name}`content` `` → a link / math / `<sub>` /
22
+ * code span / emphasis, per role.
23
+ * - **Targets** — `(label)=` on its own line before a block → a `{#label}`
24
+ * anchor on the following heading (or a bare `<a id>` otherwise), so
25
+ * `{ref}`label`` cross-references resolve.
26
+ *
27
+ * Fence-aware throughout: MyST syntax inside a plain fenced code block is
28
+ * literal and never rewritten. Anything unmapped is recorded in the
29
+ * returned `ledger` (never silent loss — same discipline as format-dita /
30
+ * format-gitbook) and passed through as best-effort text.
31
+ *
32
+ * See plans/format-myst.md.
33
+ */
34
+ export interface TranslateLedgerEntry {
35
+ /** The MyST construct that wasn't cleanly mapped. */
36
+ construct: string;
37
+ /** Human-readable note on how it was handled. */
38
+ note: string;
39
+ /** 1-based source line, when known. */
40
+ line?: number;
41
+ }
42
+ export interface TranslateResult {
43
+ markdown: string;
44
+ ledger: TranslateLedgerEntry[];
45
+ /**
46
+ * `toctree` entries collected from the body, in document order, so a
47
+ * loader can build nav without re-parsing. Each is a raw reference
48
+ * (a doc path or glob) exactly as authored.
49
+ */
50
+ toctree: string[];
51
+ }
52
+ export declare function mystToDogsbayMd(src: string): TranslateResult;
53
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B;;;;OAIG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAwID,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAM5D"}