asciidoc-abundant-tree 0.1.21 → 0.2.1
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 +29 -6
- package/dist/animation-yaml-export/cli.d.mts +2 -2
- package/dist/animation-yaml-export/cli.mjs +5 -5
- package/dist/browser.d.mts +1 -1
- package/dist/browser.mjs +244 -224
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/{export-animation-yaml-Tq1LM1lx.d.mts → export-animation-yaml-BHp1vISl.d.mts} +1 -1
- package/dist/index.d.mts +20 -3
- package/dist/index.mjs +1 -1
- package/dist/{src-DmtfeBaM.mjs → src-DMOLXZbF.mjs} +553 -388
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -191,7 +191,7 @@ Default output is a pretty tree:
|
|
|
191
191
|
|
|
192
192
|
```text
|
|
193
193
|
<document mode="single-file" sourcePath="samples/reference-links.adoc">
|
|
194
|
-
<parser name="@asciidoctor/core" version="
|
|
194
|
+
<parser name="@asciidoctor/core" version="4.1.1">
|
|
195
195
|
children[]
|
|
196
196
|
<section idOrigin="source" ids="section-basics" level=1 title="基础概念">
|
|
197
197
|
<source>
|
|
@@ -253,11 +253,11 @@ import {
|
|
|
253
253
|
serializeAbundantTreeToJson,
|
|
254
254
|
} from "asciidoc-abundant-tree";
|
|
255
255
|
|
|
256
|
-
const document = parseAbundantTree({
|
|
256
|
+
const document = await parseAbundantTree({
|
|
257
257
|
sourcePath: "docs/index.adoc",
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
const book = parseAbundantTree({
|
|
260
|
+
const book = await parseAbundantTree({
|
|
261
261
|
sourcePath: "samples/book-entry-demo/book.adoc",
|
|
262
262
|
mode: "book-entry",
|
|
263
263
|
documentRoot: "samples/book-entry-demo",
|
|
@@ -274,6 +274,29 @@ const ttl = projection.ttl;
|
|
|
274
274
|
const jsonLd = projection.jsonLd;
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
+
Book-entry callers can register include resolvers for includes that select by something other than a file path, such as a symbol in a TypeScript file. A resolver claims targets by prefix and returns whole consecutive lines of a source file inside `documentRoot`, plus the line they start at; the lines get coordinates in that file just like a file include:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
const book = await parseAbundantTree({
|
|
281
|
+
sourcePath: "bookshelf/books/08-design/book.adoc",
|
|
282
|
+
mode: "book-entry",
|
|
283
|
+
documentRoot: ".",
|
|
284
|
+
includeResolvers: [
|
|
285
|
+
{
|
|
286
|
+
// include::docloom:examples/replay.ts[symbol=replay,part=source]
|
|
287
|
+
prefix: "docloom:",
|
|
288
|
+
resolve: ({ target, attributes }) => {
|
|
289
|
+
// Your own selector: find the declaration, widen it to whole lines.
|
|
290
|
+
const { text, startLine } = selectWholeLines(target, attributes);
|
|
291
|
+
return { text, origin: { path: target, startLine } };
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
`attributes` are the include attributes as Asciidoctor parses them, the same an Asciidoctor include processor receives, so the bookshelf build and this parser can register the same selector. A resolver that throws fails construction with `include.resolver-failed`; returned text that does not match its source leaves those lines without coordinates and reports `origin-map.selection-mismatch`.
|
|
299
|
+
|
|
277
300
|
`parseAbundantTree` reads only the supplied source file. Interdocument xrefs keep their raw target and official href when Asciidoctor exposes one, but this package does not open the referenced `.adoc` file.
|
|
278
301
|
|
|
279
302
|
Browser tools that already hold AsciiDoc source text can use the browser-safe subpath:
|
|
@@ -281,7 +304,7 @@ Browser tools that already hold AsciiDoc source text can use the browser-safe su
|
|
|
281
304
|
```ts
|
|
282
305
|
import { parseAbundantTreeFromSource } from "asciidoc-abundant-tree/browser";
|
|
283
306
|
|
|
284
|
-
const document = parseAbundantTreeFromSource({
|
|
307
|
+
const document = await parseAbundantTreeFromSource({
|
|
285
308
|
sourceText,
|
|
286
309
|
sourcePath: "document.adoc",
|
|
287
310
|
});
|
|
@@ -310,7 +333,7 @@ List unresolved local xrefs:
|
|
|
310
333
|
```ts
|
|
311
334
|
import { parseAbundantTree } from "asciidoc-abundant-tree";
|
|
312
335
|
|
|
313
|
-
const document = parseAbundantTree({ sourcePath: "docs/index.adoc" });
|
|
336
|
+
const document = await parseAbundantTree({ sourcePath: "docs/index.adoc" });
|
|
314
337
|
|
|
315
338
|
for (const xref of document.xrefOccurrences) {
|
|
316
339
|
if (xref.scope === "unresolved") {
|
|
@@ -324,7 +347,7 @@ Inspect target kinds:
|
|
|
324
347
|
```ts
|
|
325
348
|
import { parseAbundantTree } from "asciidoc-abundant-tree";
|
|
326
349
|
|
|
327
|
-
const document = parseAbundantTree({ sourcePath: "docs/index.adoc" });
|
|
350
|
+
const document = await parseAbundantTree({ sourcePath: "docs/index.adoc" });
|
|
328
351
|
|
|
329
352
|
const byKind = new Map<string, number>();
|
|
330
353
|
for (const target of document.targets) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as exportAnimationYaml } from "../export-animation-yaml-
|
|
1
|
+
import { r as exportAnimationYaml } from "../export-animation-yaml-BHp1vISl.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/animation-yaml-export/cli.d.ts
|
|
4
4
|
type AnimationYamlCliResult = {
|
|
@@ -6,6 +6,6 @@ type AnimationYamlCliResult = {
|
|
|
6
6
|
readonly stdout: string;
|
|
7
7
|
readonly stderr: string;
|
|
8
8
|
};
|
|
9
|
-
declare function runAnimationYamlCli(args: string[]): AnimationYamlCliResult
|
|
9
|
+
declare function runAnimationYamlCli(args: string[]): Promise<AnimationYamlCliResult>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { AnimationYamlCliResult, exportAnimationYaml, runAnimationYamlCli };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { o as exportAnimationYaml } from "../src-
|
|
2
|
+
import { o as exportAnimationYaml } from "../src-DMOLXZbF.mjs";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
//#region src/animation-yaml-export/cli.ts
|
|
5
5
|
const USAGE = `Usage:
|
|
6
6
|
animation-yaml-export <book.adoc>
|
|
7
7
|
animation-yaml-export <book.adoc> --document-root <root>
|
|
8
8
|
animation-yaml-export --help`;
|
|
9
|
-
function runAnimationYamlCli(args) {
|
|
9
|
+
async function runAnimationYamlCli(args) {
|
|
10
10
|
let parsed;
|
|
11
11
|
try {
|
|
12
12
|
parsed = parseArgs(args);
|
|
@@ -30,10 +30,10 @@ function runAnimationYamlCli(args) {
|
|
|
30
30
|
try {
|
|
31
31
|
return {
|
|
32
32
|
code: 0,
|
|
33
|
-
stdout: exportAnimationYaml({
|
|
33
|
+
stdout: (await exportAnimationYaml({
|
|
34
34
|
sourcePath: parsed.sourcePath,
|
|
35
35
|
...parsed.documentRoot === void 0 ? {} : { documentRoot: parsed.documentRoot }
|
|
36
|
-
}).yaml,
|
|
36
|
+
})).yaml,
|
|
37
37
|
stderr: ""
|
|
38
38
|
};
|
|
39
39
|
} catch (error) {
|
|
@@ -80,7 +80,7 @@ function formatError(error) {
|
|
|
80
80
|
}
|
|
81
81
|
/* c8 ignore start */
|
|
82
82
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
83
|
-
const result = runAnimationYamlCli(process.argv.slice(2));
|
|
83
|
+
const result = await runAnimationYamlCli(process.argv.slice(2));
|
|
84
84
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
85
85
|
if (result.stderr) process.stderr.write(result.stderr.endsWith("\n") ? result.stderr : `${result.stderr}\n`);
|
|
86
86
|
process.exitCode = result.code;
|
package/dist/browser.d.mts
CHANGED
|
@@ -210,7 +210,7 @@ type ParseAbundantTreeFromSourceOptions = {
|
|
|
210
210
|
};
|
|
211
211
|
//#endregion
|
|
212
212
|
//#region src/browser-parser.d.ts
|
|
213
|
-
declare function parseAbundantTreeFromSource(options: ParseAbundantTreeFromSourceOptions): AbundantDocument
|
|
213
|
+
declare function parseAbundantTreeFromSource(options: ParseAbundantTreeFromSourceOptions): Promise<AbundantDocument>;
|
|
214
214
|
//#endregion
|
|
215
215
|
//#region src/serializers.d.ts
|
|
216
216
|
declare function formatAbundantTree(document: AbundantDocument): string;
|