@dogsbay/format-asciidoc 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/README.md +40 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +354 -0
- package/dist/cli.js.map +1 -0
- package/dist/detect.d.ts +47 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +73 -0
- package/dist/detect.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/inline-walker.d.ts +17 -0
- package/dist/inline-walker.d.ts.map +1 -0
- package/dist/inline-walker.js +167 -0
- package/dist/inline-walker.js.map +1 -0
- package/dist/loaders/antora.d.ts +3 -0
- package/dist/loaders/antora.d.ts.map +1 -0
- package/dist/loaders/antora.js +874 -0
- package/dist/loaders/antora.js.map +1 -0
- package/dist/loaders/asciibinder.d.ts +3 -0
- package/dist/loaders/asciibinder.d.ts.map +1 -0
- package/dist/loaders/asciibinder.js +229 -0
- package/dist/loaders/asciibinder.js.map +1 -0
- package/dist/loaders/dominance.d.ts +15 -0
- package/dist/loaders/dominance.d.ts.map +1 -0
- package/dist/loaders/dominance.js +86 -0
- package/dist/loaders/dominance.js.map +1 -0
- package/dist/loaders/master-adoc.d.ts +3 -0
- package/dist/loaders/master-adoc.d.ts.map +1 -0
- package/dist/loaders/master-adoc.js +178 -0
- package/dist/loaders/master-adoc.js.map +1 -0
- package/dist/loaders/plain.d.ts +3 -0
- package/dist/loaders/plain.d.ts.map +1 -0
- package/dist/loaders/plain.js +58 -0
- package/dist/loaders/plain.js.map +1 -0
- package/dist/loaders/types.d.ts +117 -0
- package/dist/loaders/types.d.ts.map +1 -0
- package/dist/loaders/types.js +2 -0
- package/dist/loaders/types.js.map +1 -0
- package/dist/loaders/util.d.ts +15 -0
- package/dist/loaders/util.d.ts.map +1 -0
- package/dist/loaders/util.js +49 -0
- package/dist/loaders/util.js.map +1 -0
- package/dist/parse.d.ts +178 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +150 -0
- package/dist/parse.js.map +1 -0
- package/dist/tree.d.ts +2 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +2 -0
- package/dist/tree.js.map +1 -0
- package/dist/walker.d.ts +8 -0
- package/dist/walker.d.ts.map +1 -0
- package/dist/walker.js +210 -0
- package/dist/walker.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @dogsbay/format-asciidoc
|
|
2
|
+
|
|
3
|
+
AsciiDoc format plugin for Dogsbay. Imports `.adoc` sources into `TreeNode[]` via a three-stage pipeline:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
AsciiDoc source
|
|
7
|
+
→ @dogsbay/adoc2md-modular (per-file engine; AsciiDoc → Markdown + Minja directives)
|
|
8
|
+
→ @dogsbay/minja (resolve {{ vars }} / {% if %} / {% include %} against an attribute context)
|
|
9
|
+
→ markdown-it + walker (Markdown → Token[] → TreeNode[])
|
|
10
|
+
TreeNode[]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Each stage is independently testable. The pipeline preserves unresolved directives (via Minja's `undefinedBehavior: "preserve"`) so a downstream pass can finish substitution when more context becomes available.
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import MarkdownIt from "markdown-it";
|
|
19
|
+
import { parseAsciidocToTree } from "@dogsbay/format-asciidoc";
|
|
20
|
+
|
|
21
|
+
const md = new MarkdownIt({ html: true, linkify: true });
|
|
22
|
+
const { tree, env } = await parseAsciidocToTree(md, adocSource, {
|
|
23
|
+
filePath: "/path/to/source.adoc", // base for include resolution
|
|
24
|
+
attributes: { product: "AAP", version: "2.5" },
|
|
25
|
+
envOverrides: { /* ... merged into env returned */ },
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Async — Minja's renderer is async (I/O for includes, timeout enforcement).
|
|
30
|
+
|
|
31
|
+
## Position in the platform
|
|
32
|
+
|
|
33
|
+
- **Each format owns its parse pipeline.** format-asciidoc does not depend on format-mkdocs; the convention in this repo is "every format converges on `TreeNode` independently" (see [`plans/format-asciidoc-import.md`](../../plans/format-asciidoc-import.md) Phase 6).
|
|
34
|
+
- Walker bootstrapped from format-mkdocs's walker as a starting reference. Diverges independently from there.
|
|
35
|
+
|
|
36
|
+
## Roadmap
|
|
37
|
+
|
|
38
|
+
- **Phase 7 (this package, current):** scaffold + `parseAsciidocToTree` + smoke tests.
|
|
39
|
+
- **Phase 8:** wire into the `dogsbay` CLI's `from:` enum + validate against AAP fixtures end-to-end.
|
|
40
|
+
- **Corpus loaders:** per-source-shape loaders (AsciiBinder topic maps, Antora playbooks, AAP master.adoc walk, plain .adoc) — see [`plans/asciidoc-corpus-loaders.md`](../../plans/asciidoc-corpus-loaders.md).
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,YAAY,EAMb,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0TzC,eAAO,MAAM,MAAM,EAAE,YA6BpB,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FormatPlugin for AsciiDoc as a source format.
|
|
3
|
+
*
|
|
4
|
+
* Phase 9a — refactored to use the CorpusLoader registry. Topology
|
|
5
|
+
* discovery lives in `loaders/{plain,master-adoc,...}.ts`; this file
|
|
6
|
+
* orchestrates loader pick → enumerate → parse-per-file → assemble
|
|
7
|
+
* ExportPage[] + NavItem[] for the CLI.
|
|
8
|
+
*
|
|
9
|
+
* The plain loader is the default fallback (matches Phase 8a
|
|
10
|
+
* behaviour byte-for-byte). The master-adoc loader picks up AAP-style
|
|
11
|
+
* `master.adoc`-rooted titles. AsciiBinder (`_topic_map.yml`) and
|
|
12
|
+
* Antora (`antora-playbook.yml`) loaders ship in Phase 9b/9c per
|
|
13
|
+
* plans/asciidoc-corpus-loaders.md.
|
|
14
|
+
*
|
|
15
|
+
* Callers can override the auto-detected loader by passing
|
|
16
|
+
* `opts.loader = "<name>"` (CLI: `--loader <name>`).
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
19
|
+
import { basename, resolve } from "node:path";
|
|
20
|
+
import MarkdownIt from "markdown-it";
|
|
21
|
+
import { parseAsciidocToTree } from "./parse.js";
|
|
22
|
+
import { pickLoader, ALL_LOADERS } from "./detect.js";
|
|
23
|
+
// Re-exported so callers (e.g. `dogsbay migrate-asciidoc`) can report
|
|
24
|
+
// which loader actually ran without duplicating detection logic.
|
|
25
|
+
export { pickLoader } from "./detect.js";
|
|
26
|
+
function prettifyName(slug) {
|
|
27
|
+
return slug
|
|
28
|
+
.split(/[-_]/)
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
31
|
+
.join(" ");
|
|
32
|
+
}
|
|
33
|
+
function slugify(text) {
|
|
34
|
+
return text
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.replace(/[^\w\s-]/g, "")
|
|
37
|
+
.trim()
|
|
38
|
+
.replace(/\s+/g, "-");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* markdown-it-attrs syntax for explicit heading anchors, trailing the
|
|
42
|
+
* heading text. AsciiDoc `[id="welcome-index"]` block anchors come
|
|
43
|
+
* through the engine as `{id="welcome-index"}`; an AsciiDoc anchor
|
|
44
|
+
* macro `[[welcome-index]]` becomes `{#welcome-index}`. Either form
|
|
45
|
+
* is valid markdown-it-attrs that an Astro render-time pass would
|
|
46
|
+
* later consume — we just need to honour it during migration so the
|
|
47
|
+
* canonical Dogsbay-MD output carries the id as `props.slug` instead
|
|
48
|
+
* of leaving a literal `{id="…"}` string in the heading text (which
|
|
49
|
+
* the dogsbay-md serializer's auto-slug step would then duplicate as
|
|
50
|
+
* a second `{#auto-slug}` block — breaking md-attrs' rule that only
|
|
51
|
+
* the *last* `{…}` block wins).
|
|
52
|
+
*
|
|
53
|
+
* Matches at end of text, capturing the id from either form:
|
|
54
|
+
* { id="foo" } → "foo"
|
|
55
|
+
* {#foo} → "foo"
|
|
56
|
+
* Tolerant of optional whitespace inside the braces.
|
|
57
|
+
*/
|
|
58
|
+
const HEADING_ID_RE = /\s*\{\s*(?:id\s*=\s*"([^"]+)"|#([^\s{}]+))\s*\}\s*$/;
|
|
59
|
+
/**
|
|
60
|
+
* Strip a trailing `{id="…"}` / `{#…}` from the last text inline of a
|
|
61
|
+
* heading and return the captured id. Mutates the inline array in
|
|
62
|
+
* place — emptied text spans are dropped so the serializer doesn't
|
|
63
|
+
* emit dangling spaces. Returns `undefined` if no marker is present.
|
|
64
|
+
*/
|
|
65
|
+
function extractHeadingId(node) {
|
|
66
|
+
const inline = node.inline;
|
|
67
|
+
if (!Array.isArray(inline) || inline.length === 0)
|
|
68
|
+
return undefined;
|
|
69
|
+
// Scan from the end for the last text span — md-attrs anchors are
|
|
70
|
+
// always at end-of-line, but trailing inline formatting (a link
|
|
71
|
+
// marker, an icon, etc.) shouldn't block detection.
|
|
72
|
+
for (let i = inline.length - 1; i >= 0; i--) {
|
|
73
|
+
const span = inline[i];
|
|
74
|
+
if (span.type !== "text")
|
|
75
|
+
continue;
|
|
76
|
+
const m = span.text.match(HEADING_ID_RE);
|
|
77
|
+
if (!m)
|
|
78
|
+
return undefined;
|
|
79
|
+
const id = m[1] ?? m[2];
|
|
80
|
+
const stripped = span.text.slice(0, span.text.length - m[0].length);
|
|
81
|
+
if (stripped.length > 0) {
|
|
82
|
+
span.text = stripped;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
inline.splice(i, 1);
|
|
86
|
+
}
|
|
87
|
+
return id;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read inline text from a heading node, cross-shape tolerant.
|
|
93
|
+
* format-asciidoc's parse.ts flattens prose wrappers (so we get the
|
|
94
|
+
* flat shape via `node.inline`), but this stays tolerant of the
|
|
95
|
+
* wrapped shape too — defence in depth in case the pipeline changes.
|
|
96
|
+
*/
|
|
97
|
+
function headingText(node) {
|
|
98
|
+
let inline;
|
|
99
|
+
if (Array.isArray(node.inline)) {
|
|
100
|
+
inline = node.inline;
|
|
101
|
+
}
|
|
102
|
+
else if (Array.isArray(node.children)) {
|
|
103
|
+
for (const child of node.children) {
|
|
104
|
+
if (child &&
|
|
105
|
+
child.type === "prose" &&
|
|
106
|
+
Array.isArray(child.inline)) {
|
|
107
|
+
inline = child.inline;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!inline)
|
|
113
|
+
return "";
|
|
114
|
+
// Text-bearing nodes only WAS text-type only — but linkify autolinks
|
|
115
|
+
// domain-like tokens INSIDE headings (`APIService
|
|
116
|
+
// [apiregistration.k8s.io/v1]` → the dotted group becomes a link), and
|
|
117
|
+
// dropping link children collapsed 240 api-reference titles to
|
|
118
|
+
// ambiguous `Kind []` (issue #059C). Collect nested inline text too.
|
|
119
|
+
const collect = (nodes) => nodes
|
|
120
|
+
.map((n) => {
|
|
121
|
+
if (n.type === "text")
|
|
122
|
+
return n.text;
|
|
123
|
+
if (n.type === "code")
|
|
124
|
+
return n.text ?? "";
|
|
125
|
+
const kids = n.children;
|
|
126
|
+
return Array.isArray(kids) ? collect(kids) : "";
|
|
127
|
+
})
|
|
128
|
+
.join("");
|
|
129
|
+
// Collecting nested nodes can now pick up DIRECTIVE tails the old
|
|
130
|
+
// text-only walk dropped silently (conditional-title assemblies emit
|
|
131
|
+
// `# Title {id="x"}{% set context %}{% endif %}` — an UNBALANCED
|
|
132
|
+
// `{% endif %}` in a frontmatter title breaks the page's minja parse
|
|
133
|
+
// and ships the page raw). Truncate at the first directive/attr block
|
|
134
|
+
// and strip trailing anchors.
|
|
135
|
+
// `{%` truncates to END (an unbalanced directive inside a quoted
|
|
136
|
+
// frontmatter title is a parse bomb — worth losing the rare heading
|
|
137
|
+
// that legitimately mentions `{% raw %}`). id/class blocks strip
|
|
138
|
+
// TRAILING-ONLY, iteratively — truncate-to-end nuked headings whose
|
|
139
|
+
// CODE SPANS contain JSONPath (`The \`{.spec.replicas}\` field`)
|
|
140
|
+
// (review). Anchors require preceding whitespace so `x^2` survives.
|
|
141
|
+
let text = collect(inline).replace(/\{%[\s\S]*$/, "");
|
|
142
|
+
let prev;
|
|
143
|
+
do {
|
|
144
|
+
prev = text;
|
|
145
|
+
text = text
|
|
146
|
+
.replace(/\s*\{id="[^"]*"\}\s*$/, "")
|
|
147
|
+
.replace(/\s*\{[.#][^}]*\}\s*$/, "")
|
|
148
|
+
.replace(/\s+\^[A-Za-z0-9-]+\s*$/, "");
|
|
149
|
+
} while (text !== prev);
|
|
150
|
+
return text.trim();
|
|
151
|
+
}
|
|
152
|
+
function extractHeadings(tree) {
|
|
153
|
+
const headings = [];
|
|
154
|
+
const seen = new Map();
|
|
155
|
+
for (const node of tree) {
|
|
156
|
+
if (node.type !== "heading")
|
|
157
|
+
continue;
|
|
158
|
+
// Honour an explicit `{id="…"}` / `{#…}` marker FIRST — strips
|
|
159
|
+
// it from inline so subsequent text reads (and the serializer's
|
|
160
|
+
// round-trip via inline) don't see the literal marker text.
|
|
161
|
+
let slug = node.props?.slug;
|
|
162
|
+
if (!slug) {
|
|
163
|
+
const explicitId = extractHeadingId(node);
|
|
164
|
+
if (explicitId) {
|
|
165
|
+
if (!node.props)
|
|
166
|
+
node.props = { level: 1 };
|
|
167
|
+
node.props.slug = explicitId;
|
|
168
|
+
slug = explicitId;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const text = headingText(node);
|
|
172
|
+
if (!slug) {
|
|
173
|
+
const baseSlug = slugify(text);
|
|
174
|
+
const count = seen.get(baseSlug) ?? 0;
|
|
175
|
+
slug = count === 0 ? baseSlug : `${baseSlug}-${count}`;
|
|
176
|
+
seen.set(baseSlug, count + 1);
|
|
177
|
+
if (!node.props)
|
|
178
|
+
node.props = { level: 1 };
|
|
179
|
+
node.props.slug = slug;
|
|
180
|
+
}
|
|
181
|
+
headings.push({
|
|
182
|
+
depth: node.props?.level ?? 1,
|
|
183
|
+
slug,
|
|
184
|
+
text,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return headings;
|
|
188
|
+
}
|
|
189
|
+
async function importAsciidoc(source, opts) {
|
|
190
|
+
if (!existsSync(source)) {
|
|
191
|
+
throw new Error(`Source directory not found: ${source}`);
|
|
192
|
+
}
|
|
193
|
+
// Phase 9a: pick a loader by topology detection (or explicit override).
|
|
194
|
+
const loaderName = typeof opts.loader === "string" ? opts.loader : undefined;
|
|
195
|
+
const topicMap = typeof opts.topicMap === "string" ? opts.topicMap : undefined;
|
|
196
|
+
// Pass topicMap into detection too — a custom-named AsciiBinder topic
|
|
197
|
+
// map must be auto-detectable, not only loadable under an explicit
|
|
198
|
+
// --loader.
|
|
199
|
+
const loader = pickLoader(source, loaderName, { topicMap });
|
|
200
|
+
const attributes = opts.attributes && typeof opts.attributes === "object"
|
|
201
|
+
? opts.attributes
|
|
202
|
+
: {};
|
|
203
|
+
const hrefPrefix = typeof opts.hrefPrefix === "string" ? opts.hrefPrefix : "";
|
|
204
|
+
const distro = typeof opts.distro === "string" ? opts.distro : undefined;
|
|
205
|
+
const loaded = await loader.load(source, {
|
|
206
|
+
hrefPrefix,
|
|
207
|
+
distro,
|
|
208
|
+
topicMap,
|
|
209
|
+
});
|
|
210
|
+
const { pages: pageSources, nav } = loaded;
|
|
211
|
+
// Antora playbook mode (#067): every loaded component root + the slug
|
|
212
|
+
// prefix its pages landed under, so migrate can mirror each component's
|
|
213
|
+
// fragments/images beneath the same prefix.
|
|
214
|
+
const components = loaded.components;
|
|
215
|
+
const sourceMounts = components?.map((c) => {
|
|
216
|
+
const segs = [];
|
|
217
|
+
if (c.name !== "ROOT")
|
|
218
|
+
segs.push(c.name);
|
|
219
|
+
if (!c.latest && c.version)
|
|
220
|
+
segs.push(c.version);
|
|
221
|
+
return { dir: resolve(source, c.startPath), prefix: segs.length ? segs.join("/") + "/" : "" };
|
|
222
|
+
});
|
|
223
|
+
// Engine map for cross-component resource IDs: the LATEST version of
|
|
224
|
+
// each component name (Antora resolves an unversioned coordinate to
|
|
225
|
+
// the latest); pages inside a versioned component still see their own
|
|
226
|
+
// component via `antoraModuleContext`.
|
|
227
|
+
const antoraComponents = components
|
|
228
|
+
? Object.fromEntries(components
|
|
229
|
+
.filter((c) => c.latest)
|
|
230
|
+
.map((c) => {
|
|
231
|
+
const segs = [];
|
|
232
|
+
if (c.name !== "ROOT")
|
|
233
|
+
segs.push(c.name);
|
|
234
|
+
return [c.name, { dir: resolve(source, c.startPath), prefix: segs.length ? segs.join("/") + "/" : "" }];
|
|
235
|
+
}))
|
|
236
|
+
: undefined;
|
|
237
|
+
const md = new MarkdownIt({ html: true, linkify: true });
|
|
238
|
+
const pages = [];
|
|
239
|
+
// Per-page fail-soft. A 20k-page corpus migration can't tolerate a
|
|
240
|
+
// single broken page (filesystem race, malformed AsciiDoc construct
|
|
241
|
+
// the engine doesn't recognise, etc.) crashing the entire run. Log
|
|
242
|
+
// the failure with its slug and source path, drop the page, keep
|
|
243
|
+
// going. At the end report a one-line summary so the user sees
|
|
244
|
+
// exactly how many pages didn't make it. Note: parseAsciidocToTree
|
|
245
|
+
// already swallows Minja-stage errors and falls back to the raw
|
|
246
|
+
// engine output (preserves directives verbatim), so anything that
|
|
247
|
+
// reaches *this* catch is a hard failure earlier in the pipeline
|
|
248
|
+
// (engine throw, markdown-it crash, etc.) — rare but real.
|
|
249
|
+
let failed = 0;
|
|
250
|
+
for (const ps of pageSources) {
|
|
251
|
+
try {
|
|
252
|
+
const content = readFileSync(ps.filePath, "utf-8");
|
|
253
|
+
const pageAttrs = ps.attributes
|
|
254
|
+
? { ...attributes, ...ps.attributes }
|
|
255
|
+
: attributes;
|
|
256
|
+
const { tree, intermediateMd } = await parseAsciidocToTree(md, content, {
|
|
257
|
+
filePath: ps.filePath,
|
|
258
|
+
// `{% include %}` targets must stay inside the corpus (#027) —
|
|
259
|
+
// a crafted include in a third-party docs repo would otherwise
|
|
260
|
+
// read arbitrary files into the migrated output. Symlinked
|
|
261
|
+
// topology (AsciiBinder `_attributes -> ../_attributes/`) stays
|
|
262
|
+
// legal as long as the target realpath is inside the corpus.
|
|
263
|
+
includeRoot: opts.allowOutOfRootIncludes === true ? undefined : resolve(source),
|
|
264
|
+
attributes: pageAttrs,
|
|
265
|
+
// Slug is the docroot-relative position; the engine uses it to
|
|
266
|
+
// resolve cross-doc xref hrefs to root-relative (Antora-style)
|
|
267
|
+
// instead of file-relative. See plans/xref-absolute-hrefs.md.
|
|
268
|
+
sourcePath: ps.slug,
|
|
269
|
+
// Antora corpora get module-coordinate xref translation +
|
|
270
|
+
// resource-ID include resolution in the engine.
|
|
271
|
+
antora: loader.name === "antora",
|
|
272
|
+
...(antoraComponents ? { antoraComponents } : {}),
|
|
273
|
+
// Opt-in by the caller (migrate-asciidoc): its `bodyMarkdown`
|
|
274
|
+
// output is dogsbay-md parsed downstream WITH markdown-it-attrs,
|
|
275
|
+
// so block roles become real classes and role-styled badges keep
|
|
276
|
+
// their span — matching what its FRAGMENT path always did (a page
|
|
277
|
+
// and its own fragment copy disagreed on every role, #076). OFF
|
|
278
|
+
// for the tree path (`convert`/`site build` from asciidoc), whose
|
|
279
|
+
// markdown-it deliberately excludes md-attrs — `{.role}` would
|
|
280
|
+
// land in the TreeNode as literal text.
|
|
281
|
+
blockRoles: opts.blockRoles === true,
|
|
282
|
+
// Corpus distro flags the migrate knows are false — conditional
|
|
283
|
+
// STATE tracking in the engine (never drops text).
|
|
284
|
+
falseAttributes: Array.isArray(opts.falseAttributes)
|
|
285
|
+
? opts.falseAttributes
|
|
286
|
+
: [],
|
|
287
|
+
clampRowspans: opts.clampRowspans === true,
|
|
288
|
+
});
|
|
289
|
+
const headings = extractHeadings(tree);
|
|
290
|
+
const h1 = headings.find((h) => h.depth === 1);
|
|
291
|
+
const title = h1?.text || prettifyName(basename(ps.slug));
|
|
292
|
+
pages.push({
|
|
293
|
+
slug: ps.slug,
|
|
294
|
+
title,
|
|
295
|
+
tree,
|
|
296
|
+
headings,
|
|
297
|
+
frontmatter: {},
|
|
298
|
+
meta: {},
|
|
299
|
+
// `bodyMarkdown` is what migrate-asciidoc writes to disk —
|
|
300
|
+
// engine output + Minja preserve, paragraph structure of
|
|
301
|
+
// the source `.adoc` intact. Bypasses the markdown-it →
|
|
302
|
+
// format-dogsbay-md round-trip that would otherwise fold
|
|
303
|
+
// adjacent non-blank lines into one squashed paragraph.
|
|
304
|
+
// The TreeNode + headings stay as canonical for the runtime
|
|
305
|
+
// path (format-astro emit). See plans/multi-variant-builds.md
|
|
306
|
+
// for the broader migration-vs-runtime split.
|
|
307
|
+
bodyMarkdown: intermediateMd,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
failed += 1;
|
|
312
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
313
|
+
console.warn(`asciidoc import: failed to convert ${ps.filePath} (slug "${ps.slug}"), skipping: ${msg}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (failed > 0) {
|
|
317
|
+
console.warn(`asciidoc import: ${failed} of ${pageSources.length} page(s) failed to convert and were skipped`);
|
|
318
|
+
}
|
|
319
|
+
const corpusAttributes = loaded.corpusAttributes;
|
|
320
|
+
return {
|
|
321
|
+
pages, nav,
|
|
322
|
+
...(sourceMounts ? { sourceMounts } : {}),
|
|
323
|
+
...(antoraComponents ? { antoraComponents } : {}),
|
|
324
|
+
...(corpusAttributes ? { corpusAttributes } : {}),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
export const plugin = {
|
|
328
|
+
name: "asciidoc",
|
|
329
|
+
canImport: true,
|
|
330
|
+
canExport: false,
|
|
331
|
+
detectSource: (path) => {
|
|
332
|
+
// The plugin's overall detect = any registered loader detects.
|
|
333
|
+
return ALL_LOADERS.some((l) => l.detect(path));
|
|
334
|
+
},
|
|
335
|
+
importOptions: [
|
|
336
|
+
{
|
|
337
|
+
flags: "--loader <name>",
|
|
338
|
+
description: "Force a specific corpus loader (plain, master-adoc, asciibinder, antora). Auto-detected when omitted.",
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
flags: "--distro <name>",
|
|
342
|
+
description: "AsciiBinder distro filter (e.g. 'openshift-enterprise'). Drops topic_map entries whose Distros: list excludes this value; entries without Distros: are kept as universal.",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
flags: "--topic-map <path>",
|
|
346
|
+
description: "AsciiBinder topic-map path, relative to the source root (default: _topic_maps/_topic_map.yml). Used for both detection and loading.",
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
exportOptions: [],
|
|
350
|
+
async import(source, opts) {
|
|
351
|
+
return importAsciidoc(source, opts);
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,UAAU,MAAM,aAAa,CAAC;AASrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAA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B;YAC3B,WAAW,EACT,qIAAqI;SACxI;KACF;IACD,aAAa,EAAE,EAAE;IACjB,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,IAA6B;QACxD,OAAO,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;CACF,CAAC"}
|
package/dist/detect.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader detection + selection.
|
|
3
|
+
*
|
|
4
|
+
* Ordered most-specific first: Antora → AsciiBinder → master.adoc
|
|
5
|
+
* → plain. First loader whose `detect()` returns true wins.
|
|
6
|
+
*
|
|
7
|
+
* Callers can override via the `loader` option (CLI: `--loader <name>`)
|
|
8
|
+
* — useful when the precedence list silently picks the wrong loader
|
|
9
|
+
* (e.g. a repo with both a master.adoc and a _topic_map.yml).
|
|
10
|
+
*
|
|
11
|
+
* Phase 9a ships plain + master-adoc. Phase 9b adds asciibinder.
|
|
12
|
+
* Phase 9c adds antora. Until they ship, this list contains only
|
|
13
|
+
* the loaders that exist; detection still works — the absent ones
|
|
14
|
+
* just never claim a corpus.
|
|
15
|
+
*/
|
|
16
|
+
import type { CorpusLoader, LoaderOpts } from "./loaders/types.js";
|
|
17
|
+
/**
|
|
18
|
+
* Loaders in detection-precedence order (most specific first).
|
|
19
|
+
* The plain loader is the catch-all and stays last.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ALL_LOADERS: CorpusLoader[];
|
|
22
|
+
export declare class LoaderNotFoundError extends Error {
|
|
23
|
+
readonly requested: string;
|
|
24
|
+
readonly available: string[];
|
|
25
|
+
constructor(requested: string, available: string[]);
|
|
26
|
+
}
|
|
27
|
+
export declare class NoLoaderMatchedError extends Error {
|
|
28
|
+
readonly sourceDir: string;
|
|
29
|
+
constructor(sourceDir: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Pick the loader to use for a given source dir.
|
|
33
|
+
*
|
|
34
|
+
* - `override` (CLI `--loader <name>`) always wins; throws
|
|
35
|
+
* LoaderNotFoundError if the name doesn't match a registered loader.
|
|
36
|
+
* - Otherwise runs each loader's `detect()` in precedence order;
|
|
37
|
+
* first match wins.
|
|
38
|
+
* - Falls back to the plain loader when nothing detects. Reaching this
|
|
39
|
+
* function means the caller already declared the source to be AsciiDoc, so
|
|
40
|
+
* a failed TOPOLOGY guess must not become a failed conversion.
|
|
41
|
+
*
|
|
42
|
+
* `opts` is forwarded to each `detect()` so overrides that affect
|
|
43
|
+
* detection (e.g. a non-default AsciiBinder `topicMap` name) are
|
|
44
|
+
* honoured during auto-detection, not just during `load()`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pickLoader(sourceDir: string, override?: string, opts?: LoaderOpts): CorpusLoader;
|
|
47
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMnE;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,YAAY,EAKrC,CAAC;AAEF,qBAAa,mBAAoB,SAAQ,KAAK;aAChB,SAAS,EAAE,MAAM;aAAkB,SAAS,EAAE,MAAM,EAAE;gBAAtD,SAAS,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM,EAAE;CAKnF;AAED,qBAAa,oBAAqB,SAAQ,KAAK;aACjB,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAO9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,UAAU,GAChB,YAAY,CA0Bd"}
|
package/dist/detect.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { plainLoader } from "./loaders/plain.js";
|
|
2
|
+
import { masterAdocLoader } from "./loaders/master-adoc.js";
|
|
3
|
+
import { asciibinderLoader } from "./loaders/asciibinder.js";
|
|
4
|
+
import { antoraLoader } from "./loaders/antora.js";
|
|
5
|
+
/**
|
|
6
|
+
* Loaders in detection-precedence order (most specific first).
|
|
7
|
+
* The plain loader is the catch-all and stays last.
|
|
8
|
+
*/
|
|
9
|
+
export const ALL_LOADERS = [
|
|
10
|
+
antoraLoader,
|
|
11
|
+
asciibinderLoader,
|
|
12
|
+
masterAdocLoader,
|
|
13
|
+
plainLoader,
|
|
14
|
+
];
|
|
15
|
+
export class LoaderNotFoundError extends Error {
|
|
16
|
+
requested;
|
|
17
|
+
available;
|
|
18
|
+
constructor(requested, available) {
|
|
19
|
+
super(`Unknown asciidoc loader "${requested}". Available: ${available.join(", ")}.`);
|
|
20
|
+
this.requested = requested;
|
|
21
|
+
this.available = available;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class NoLoaderMatchedError extends Error {
|
|
25
|
+
sourceDir;
|
|
26
|
+
constructor(sourceDir) {
|
|
27
|
+
super(`No asciidoc loader matched the source at ${sourceDir}. ` +
|
|
28
|
+
`Tried ${ALL_LOADERS.map((l) => l.name).join(", ")}. ` +
|
|
29
|
+
`Pass --loader <name> to force a specific loader.`);
|
|
30
|
+
this.sourceDir = sourceDir;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Pick the loader to use for a given source dir.
|
|
35
|
+
*
|
|
36
|
+
* - `override` (CLI `--loader <name>`) always wins; throws
|
|
37
|
+
* LoaderNotFoundError if the name doesn't match a registered loader.
|
|
38
|
+
* - Otherwise runs each loader's `detect()` in precedence order;
|
|
39
|
+
* first match wins.
|
|
40
|
+
* - Falls back to the plain loader when nothing detects. Reaching this
|
|
41
|
+
* function means the caller already declared the source to be AsciiDoc, so
|
|
42
|
+
* a failed TOPOLOGY guess must not become a failed conversion.
|
|
43
|
+
*
|
|
44
|
+
* `opts` is forwarded to each `detect()` so overrides that affect
|
|
45
|
+
* detection (e.g. a non-default AsciiBinder `topicMap` name) are
|
|
46
|
+
* honoured during auto-detection, not just during `load()`.
|
|
47
|
+
*/
|
|
48
|
+
export function pickLoader(sourceDir, override, opts) {
|
|
49
|
+
if (override) {
|
|
50
|
+
const match = ALL_LOADERS.find((l) => l.name === override);
|
|
51
|
+
if (!match) {
|
|
52
|
+
throw new LoaderNotFoundError(override, ALL_LOADERS.map((l) => l.name));
|
|
53
|
+
}
|
|
54
|
+
return match;
|
|
55
|
+
}
|
|
56
|
+
const match = ALL_LOADERS.find((l) => l.detect(sourceDir, opts));
|
|
57
|
+
if (match)
|
|
58
|
+
return match;
|
|
59
|
+
// Nothing DETECTED — but reaching this function already means the caller
|
|
60
|
+
// decided this is an AsciiDoc corpus (`--from asciidoc`, or a config
|
|
61
|
+
// `from: asciidoc`). Detection is a convenience for guessing the format;
|
|
62
|
+
// once the user has stated it, refusing to load is the tool arguing with
|
|
63
|
+
// someone who knows their own docs.
|
|
64
|
+
//
|
|
65
|
+
// This used to throw NoLoaderMatchedError, which nothing catches — so
|
|
66
|
+
// `convert --from asciidoc` on a corpus the dominance heuristic declines
|
|
67
|
+
// (a couple of `.adoc` files beside several `.md`) exited with a raw Node
|
|
68
|
+
// stack trace instead of converting. The plain loader is the catch-all and
|
|
69
|
+
// handles exactly that corpus fine; `--loader <name>` still forces a
|
|
70
|
+
// specific one.
|
|
71
|
+
return plainLoader;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY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AAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACjE,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,yEAAyE;IACzE,qEAAqE;IACrE,yEAAyE;IACzE,yEAAyE;IACzE,oCAAoC;IACpC,EAAE;IACF,sEAAsE;IACtE,yEAAyE;IACzE,0EAA0E;IAC1E,2EAA2E;IAC3E,qEAAqE;IACrE,gBAAgB;IAChB,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dogsbay/format-asciidoc
|
|
3
|
+
*
|
|
4
|
+
* AsciiDoc format plugin — imports `.adoc` sources into `TreeNode[]`.
|
|
5
|
+
* See plans/format-asciidoc-import.md for the full architecture.
|
|
6
|
+
*/
|
|
7
|
+
export { parseAsciidocToTree, type ParseAsciidocOptions } from "./parse.js";
|
|
8
|
+
export { tokensToTree } from "./walker.js";
|
|
9
|
+
export type { TreeNode } from "./tree.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dogsbay/format-asciidoc
|
|
3
|
+
*
|
|
4
|
+
* AsciiDoc format plugin — imports `.adoc` sources into `TreeNode[]`.
|
|
5
|
+
* See plans/format-asciidoc-import.md for the full architecture.
|
|
6
|
+
*/
|
|
7
|
+
export { parseAsciidocToTree } from "./parse.js";
|
|
8
|
+
export { tokensToTree } from "./walker.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAA6B,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline token walker — converts markdown-it inline tokens into InlineNode[].
|
|
3
|
+
*
|
|
4
|
+
* Walks tokens left-to-right maintaining an annotation stack (bold/italic/
|
|
5
|
+
* strikethrough) and a container stack for links. Emits InlineNode spans
|
|
6
|
+
* as it encounters content tokens.
|
|
7
|
+
*
|
|
8
|
+
* Formatting is flat annotations on text spans (Notion model), not nested
|
|
9
|
+
* elements. `{ bold: true, italic: true }` instead of `<strong><em>`.
|
|
10
|
+
*/
|
|
11
|
+
import type Token from "markdown-it/lib/token.mjs";
|
|
12
|
+
import type { InlineNode } from "@dogsbay/types";
|
|
13
|
+
/**
|
|
14
|
+
* Convert markdown-it inline token children into structured InlineNode[].
|
|
15
|
+
*/
|
|
16
|
+
export declare function walkInlineTokens(tokens: Token[] | null): InlineNode[];
|
|
17
|
+
//# sourceMappingURL=inline-walker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-walker.d.ts","sourceRoot":"","sources":["../src/inline-walker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,MAAM,2BAA2B,CAAC;AACnD,OAAO,KAAK,EACV,UAAU,EAWX,MAAM,gBAAgB,CAAC;AAQxB;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,GAAG,UAAU,EAAE,CA2KrE"}
|