asciidoctor 4.0.0-alpha.2 → 4.0.0-alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asciidoctor",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.3",
4
4
  "description": "A JavaScript AsciiDoc processor powered by Asciidoctor",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "test": "node --test test/cli.test.js",
17
+ "test:deno": "deno test --allow-env --no-check --allow-read --allow-sys --allow-write --allow-run --allow-net test/cli.test.js",
17
18
  "lint": "biome lint bin lib tasks index.js rollup.config.js",
18
19
  "format": "biome format --write bin lib tasks index.js rollup.config.js",
19
20
  "build:bundle": "rollup -c",
@@ -53,11 +54,11 @@
53
54
  },
54
55
  "homepage": "https://github.com/asciidoctor/asciidoctor.js",
55
56
  "dependencies": {
56
- "@asciidoctor/core": "4.0.0-alpha.2"
57
+ "@asciidoctor/core": "4.0.0-alpha.3"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@biomejs/biome": "^2.4.13",
60
- "@rollup/plugin-commonjs": "^28.0.9",
61
+ "@rollup/plugin-commonjs": "^29.0.0",
61
62
  "@rollup/plugin-node-resolve": "^16.0.3",
62
63
  "ejs": "^3.1.10",
63
64
  "handlebars": "^4.7.8",
@@ -66,6 +67,6 @@
66
67
  "pug": "^3.0.3"
67
68
  },
68
69
  "volta": {
69
- "node": "24.14.1"
70
+ "node": "24.15.0"
70
71
  }
71
72
  }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Return the attribute entries stored for the given block attributes object,
3
+ * or undefined if none have been saved.
4
+ * @param {Object} blockAttributes
5
+ * @returns {AttributeEntry[]|undefined}
6
+ */
7
+ export function getAttributeEntries(blockAttributes: any): AttributeEntry[] | undefined;
8
+ export const ATTR_ENTRIES_KEY: unique symbol;
1
9
  export class AttributeEntry {
2
10
  constructor(name: any, value: any, negate?: any);
3
11
  name: any;
@@ -7,7 +7,7 @@
7
7
  * 1. target starts with file:// → inc_path = relpath = target
8
8
  * 2. target is a URI → must descend from baseDir or allow-uri-read; else → link
9
9
  * 3. target is an absolute OS path → prepend file:// (or file:///)
10
- * 4. baseDir == '.' → inc_path = relpath = target (resolved by XMLHttpRequest/fetch)
10
+ * 4. baseDir == '.' → inc_path = relpath = target (resolved by fetch)
11
11
  * 5. baseDir starts with file:// OR baseDir is not a URI → inc_path = baseDir/target; relpath = target
12
12
  * 6. baseDir is an absolute URL → inc_path = baseDir/target; relpath = target
13
13
  *
@@ -224,7 +224,12 @@ export class Processor {
224
224
  * Extensions.register(function () { this.preprocessor(CommentStripPreprocessor) })
225
225
  */
226
226
  export class Preprocessor extends Processor {
227
- process(_document: any, _reader: any): void;
227
+ /**
228
+ * @param {Document} document - The document being parsed.
229
+ * @param {Reader} reader - The reader positioned at the beginning of the source.
230
+ * @returns {Reader|undefined} The same or a substitute Reader, or undefined to use the original.
231
+ */
232
+ process(document: Document, reader: Reader): Reader | undefined;
228
233
  }
229
234
  export namespace Preprocessor {
230
235
  export { DocumentProcessorDsl as DSL };
@@ -246,7 +251,11 @@ export namespace Preprocessor {
246
251
  * Extensions.register(function () { this.treeProcessor(ShoutTreeProcessor) })
247
252
  */
248
253
  export class TreeProcessor extends Processor {
249
- process(_document: any): void;
254
+ /**
255
+ * @param {Document} document - The parsed document.
256
+ * @returns {void}
257
+ */
258
+ process(document: Document): void;
250
259
  }
251
260
  export namespace TreeProcessor {
252
261
  export { DocumentProcessorDsl as DSL };
@@ -271,7 +280,12 @@ export const Treeprocessor: typeof TreeProcessor;
271
280
  * Extensions.register(function () { this.postprocessor(FooterPostprocessor) })
272
281
  */
273
282
  export class Postprocessor extends Processor {
274
- process(_document: any, _output: any): void;
283
+ /**
284
+ * @param {Document} document - The converted document.
285
+ * @param {string} output - The converted output string.
286
+ * @returns {string} The (possibly modified) output string.
287
+ */
288
+ process(document: Document, output: string): string;
275
289
  }
276
290
  export namespace Postprocessor {
277
291
  export { DocumentProcessorDsl as DSL };
@@ -282,8 +296,20 @@ export namespace Postprocessor {
282
296
  * Implementations must extend IncludeProcessor.
283
297
  */
284
298
  export class IncludeProcessor extends Processor {
285
- process(_document: any, _reader: any, _target: any, _attributes: any): void;
286
- handles(_doc: any, _target: any): boolean;
299
+ /**
300
+ * @param {Document} document - The document being parsed.
301
+ * @param {Reader} reader - The reader for the including document.
302
+ * @param {string} target - The target of the include directive.
303
+ * @param {Record<string, string>} attributes - The parsed include attributes.
304
+ * @returns {void}
305
+ */
306
+ process(document: Document, reader: Reader, target: string, attributes: Record<string, string>): void;
307
+ /**
308
+ * @param {Document} doc - The document being parsed.
309
+ * @param {string} target - The target of the include directive.
310
+ * @returns {boolean} true if this processor handles the given target.
311
+ */
312
+ handles(doc: Document, target: string): boolean;
287
313
  }
288
314
  export namespace IncludeProcessor {
289
315
  export { IncludeProcessorDsl as DSL };
@@ -295,7 +321,11 @@ export namespace IncludeProcessor {
295
321
  * Implementations must extend DocinfoProcessor.
296
322
  */
297
323
  export class DocinfoProcessor extends Processor {
298
- process(_document: any): void;
324
+ /**
325
+ * @param {Document} document - The document being converted.
326
+ * @returns {string} The docinfo content to inject into the document.
327
+ */
328
+ process(document: Document): string;
299
329
  }
300
330
  export namespace DocinfoProcessor {
301
331
  export { DocinfoProcessorDsl as DSL };
@@ -331,7 +361,13 @@ export namespace DocinfoProcessor {
331
361
  export class BlockProcessor extends Processor {
332
362
  constructor(name?: any, config?: {});
333
363
  name: any;
334
- process(_parent: any, _reader: any, _attributes: any): void;
364
+ /**
365
+ * @param {AbstractBlock} parent - The enclosing block.
366
+ * @param {Reader} reader - The reader positioned at the block content.
367
+ * @param {Record<string, unknown>} attributes - The parsed block attributes.
368
+ * @returns {Block|void} A block node, or void to let the parser handle it.
369
+ */
370
+ process(parent: AbstractBlock, reader: Reader, attributes: Record<string, unknown>): Block | void;
335
371
  }
336
372
  export namespace BlockProcessor {
337
373
  export { BlockProcessorDsl as DSL };
@@ -342,7 +378,13 @@ export namespace BlockProcessor {
342
378
  export class MacroProcessor extends Processor {
343
379
  constructor(name?: any, config?: {});
344
380
  name: any;
345
- process(_parent: any, _target: any, _attributes: any): void;
381
+ /**
382
+ * @param {AbstractBlock} parent - The enclosing block.
383
+ * @param {string} target - The macro target (text between `name:` and `[`).
384
+ * @param {Record<string, unknown>} attributes - The parsed macro attributes.
385
+ * @returns {Block|Inline|void}
386
+ */
387
+ process(parent: AbstractBlock, target: string, attributes: Record<string, unknown>): Block | Inline | void;
346
388
  }
347
389
  /**
348
390
  * BlockMacroProcessors handle block macros with a custom name.
@@ -370,6 +412,13 @@ export class MacroProcessor extends Processor {
370
412
  */
371
413
  export class BlockMacroProcessor extends MacroProcessor {
372
414
  _name: any;
415
+ /**
416
+ * @param {AbstractBlock} parent - The enclosing block.
417
+ * @param {string} target - The macro target.
418
+ * @param {Record<string, unknown>} attributes - The parsed macro attributes.
419
+ * @returns {Block} A block node created with one of the `createBlock` helpers.
420
+ */
421
+ process(parent: AbstractBlock, target: string, attributes: Record<string, unknown>): Block;
373
422
  }
374
423
  export namespace BlockMacroProcessor {
375
424
  export { MacroProcessorDsl as DSL };
@@ -407,6 +456,13 @@ export class InlineMacroProcessor extends MacroProcessor {
407
456
  * @returns {RegExp}
408
457
  */
409
458
  get regexp(): RegExp;
459
+ /**
460
+ * @param {AbstractBlock} parent - The enclosing block.
461
+ * @param {string} target - The macro target.
462
+ * @param {Record<string, unknown>} attributes - The parsed macro attributes.
463
+ * @returns {Inline} An Inline node created with `this.createInline(...)`.
464
+ */
465
+ process(parent: AbstractBlock, target: string, attributes: Record<string, unknown>): Inline;
410
466
  resolveRegexp(name: any, format: any): any;
411
467
  }
412
468
  export namespace InlineMacroProcessor {
@@ -456,7 +512,7 @@ export class Registry {
456
512
  * @returns {Registry} this Registry.
457
513
  */
458
514
  activate(document: Document): Registry;
459
- document: any;
515
+ document: import("./document.js").Document;
460
516
  /**
461
517
  * Register a Preprocessor with the extension registry.
462
518
  *
@@ -609,6 +665,12 @@ export class Registry {
609
665
  * @returns {boolean}
610
666
  */
611
667
  hasBlocks(): boolean;
668
+ /**
669
+ * Retrieve all BlockProcessor Extension proxy objects.
670
+ *
671
+ * @returns {ProcessorExtension[]}
672
+ */
673
+ blocks(): ProcessorExtension[];
612
674
  /**
613
675
  * Check whether a BlockProcessor is registered for the given name and context.
614
676
  *
@@ -639,6 +701,12 @@ export class Registry {
639
701
  * @returns {boolean}
640
702
  */
641
703
  hasBlockMacros(): boolean;
704
+ /**
705
+ * Retrieve all BlockMacroProcessor Extension proxy objects.
706
+ *
707
+ * @returns {ProcessorExtension[]}
708
+ */
709
+ blockMacros(): ProcessorExtension[];
642
710
  /**
643
711
  * Check whether a BlockMacroProcessor is registered for the given name.
644
712
  *
@@ -700,6 +768,47 @@ export class Registry {
700
768
  * @returns {ProcessorExtension} the Extension stored in the registry.
701
769
  */
702
770
  prefer(...args: any[]): ProcessorExtension;
771
+ /** @returns {object} the plain Object that maps names to groups for this registry. */
772
+ getGroups(): object;
773
+ /** Alias for {@link preprocessors}. */
774
+ getPreprocessors(): ProcessorExtension[];
775
+ /** Alias for {@link treeProcessors}. */
776
+ getTreeProcessors(): ProcessorExtension[];
777
+ /** Alias for {@link includeProcessors}. */
778
+ getIncludeProcessors(): ProcessorExtension[];
779
+ /** Alias for {@link postprocessors}. */
780
+ getPostprocessors(): ProcessorExtension[];
781
+ /**
782
+ * Alias for {@link docinfoProcessors}.
783
+ *
784
+ * @param {string|null} [location=null]
785
+ */
786
+ getDocinfoProcessors(location?: string | null): ProcessorExtension[];
787
+ /** Alias for {@link blocks}. */
788
+ getBlocks(): ProcessorExtension[];
789
+ /** Alias for {@link blockMacros}. */
790
+ getBlockMacros(): ProcessorExtension[];
791
+ /** Alias for {@link inlineMacros}. */
792
+ getInlineMacros(): ProcessorExtension[];
793
+ /**
794
+ * Alias for {@link registeredForInlineMacro}.
795
+ *
796
+ * @param {string} name
797
+ */
798
+ getInlineMacroFor(name: string): false | ProcessorExtension;
799
+ /**
800
+ * Alias for {@link registeredForBlock}.
801
+ *
802
+ * @param {string} name
803
+ * @param {string} context
804
+ */
805
+ getBlockFor(name: string, context: string): false | ProcessorExtension;
806
+ /**
807
+ * Alias for {@link registeredForBlockMacro}.
808
+ *
809
+ * @param {string} name
810
+ */
811
+ getBlockMacroFor(name: string): false | ProcessorExtension;
703
812
  }
704
813
  export namespace Extensions {
705
814
  /**
@@ -708,6 +817,12 @@ export namespace Extensions {
708
817
  * @returns {object}
709
818
  */
710
819
  function groups(): object;
820
+ /**
821
+ * Alias for {@link groups}.
822
+ *
823
+ * @returns {object}
824
+ */
825
+ function getGroups(): object;
711
826
  /**
712
827
  * Create a new Registry, optionally pre-populated with a named block.
713
828
  *
@@ -868,6 +983,85 @@ export namespace Extensions {
868
983
  */
869
984
  function newBlockMacroProcessor(name?: string, functions?: object, ...args: any[]): BlockMacroProcessor;
870
985
  }
986
+ export type Document = import("./document.js").Document;
987
+ export type AbstractBlock = import("./abstract_block.js").AbstractBlock;
988
+ /**
989
+ * DSL interface for configuring a {@link Processor} instance.
990
+ * Applied to a processor instance via `Object.assign(instance, DslMixin)`.
991
+ *
992
+ * The `process` property behaves as a setter when called with a single Function
993
+ * argument (stores the process block), or as a passthrough caller otherwise.
994
+ */
995
+ export type ProcessorDslInterface = {
996
+ /**
997
+ * - Set a config option.
998
+ */
999
+ option: (key: string, value: unknown) => void;
1000
+ /**
1001
+ * - Register the process function.
1002
+ */
1003
+ process: (fn: (...args: unknown[]) => unknown) => void;
1004
+ /**
1005
+ * - Returns true if a process function has been registered.
1006
+ */
1007
+ processBlockGiven: () => boolean;
1008
+ };
1009
+ /**
1010
+ * DSL interface for document processors (Preprocessor, TreeProcessor, Postprocessor, DocinfoProcessor).
1011
+ */
1012
+ export type DocumentProcessorDslInterface = ProcessorDslInterface & {
1013
+ prefer(): void;
1014
+ prepend(): void;
1015
+ };
1016
+ /**
1017
+ * DSL interface for syntax processors (BlockProcessor, BlockMacroProcessor, InlineMacroProcessor).
1018
+ */
1019
+ export type SyntaxProcessorDslInterface = ProcessorDslInterface & {
1020
+ named(value: string): void;
1021
+ contentModel(value: string): void;
1022
+ parseContentAs(value: string): void;
1023
+ positionalAttributes(...value: string[]): void;
1024
+ namePositionalAttributes(...value: string[]): void;
1025
+ positionalAttrs(...value: string[]): void;
1026
+ defaultAttributes(value: Record<string, string>): void;
1027
+ defaultAttrs(value: Record<string, string>): void;
1028
+ resolveAttributes(...args: unknown[]): void;
1029
+ resolvesAttributes(...args: unknown[]): void;
1030
+ };
1031
+ /**
1032
+ * DSL interface for include processors.
1033
+ */
1034
+ export type IncludeProcessorDslInterface = DocumentProcessorDslInterface & {
1035
+ handles(fn: (doc: Document, target: string) => boolean): void;
1036
+ };
1037
+ /**
1038
+ * DSL interface for docinfo processors.
1039
+ */
1040
+ export type DocinfoProcessorDslInterface = DocumentProcessorDslInterface & {
1041
+ atLocation(value: string): void;
1042
+ };
1043
+ /**
1044
+ * DSL interface for block processors.
1045
+ */
1046
+ export type BlockProcessorDslInterface = SyntaxProcessorDslInterface & {
1047
+ contexts(...value: (string | string[])[]): void;
1048
+ onContexts(...value: (string | string[])[]): void;
1049
+ onContext(...value: (string | string[])[]): void;
1050
+ bindTo(...value: (string | string[])[]): void;
1051
+ };
1052
+ /**
1053
+ * DSL interface for macro processors (block and inline macros).
1054
+ */
1055
+ export type MacroProcessorDslInterface = SyntaxProcessorDslInterface;
1056
+ /**
1057
+ * DSL interface for inline macro processors.
1058
+ */
1059
+ export type InlineMacroProcessorDslInterface = MacroProcessorDslInterface & {
1060
+ format(value: string): void;
1061
+ matchFormat(value: string): void;
1062
+ usingFormat(value: string): void;
1063
+ match(value: RegExp): void;
1064
+ };
871
1065
  import { Section } from './section.js';
872
1066
  import { Block } from './block.js';
873
1067
  import { List } from './list.js';
package/types/index.d.cts CHANGED
@@ -27,6 +27,14 @@ export function load(input: string | string[] | Buffer, options?: any): Promise<
27
27
  * @returns {Promise<Document>} - the parsed Document
28
28
  */
29
29
  export function loadFile(filename: string, options?: any): Promise<Document>;
30
+ export type ProcessorDslInterface = import("./extensions.js").ProcessorDslInterface;
31
+ export type DocumentProcessorDslInterface = import("./extensions.js").DocumentProcessorDslInterface;
32
+ export type SyntaxProcessorDslInterface = import("./extensions.js").SyntaxProcessorDslInterface;
33
+ export type IncludeProcessorDslInterface = import("./extensions.js").IncludeProcessorDslInterface;
34
+ export type DocinfoProcessorDslInterface = import("./extensions.js").DocinfoProcessorDslInterface;
35
+ export type BlockProcessorDslInterface = import("./extensions.js").BlockProcessorDslInterface;
36
+ export type MacroProcessorDslInterface = import("./extensions.js").MacroProcessorDslInterface;
37
+ export type InlineMacroProcessorDslInterface = import("./extensions.js").InlineMacroProcessorDslInterface;
30
38
  import { Document } from './document.js';
31
39
  import { convert } from './convert.js';
32
40
  import { convertFile } from './convert.js';
package/types/index.d.ts CHANGED
@@ -26,6 +26,14 @@ export function load(input: string | string[] | Buffer, options?: any): Promise<
26
26
  * @returns {Promise<Document>} - the parsed Document
27
27
  */
28
28
  export function loadFile(filename: string, options?: any): Promise<Document>;
29
+ export type ProcessorDslInterface = import("./extensions.js").ProcessorDslInterface;
30
+ export type DocumentProcessorDslInterface = import("./extensions.js").DocumentProcessorDslInterface;
31
+ export type SyntaxProcessorDslInterface = import("./extensions.js").SyntaxProcessorDslInterface;
32
+ export type IncludeProcessorDslInterface = import("./extensions.js").IncludeProcessorDslInterface;
33
+ export type DocinfoProcessorDslInterface = import("./extensions.js").DocinfoProcessorDslInterface;
34
+ export type BlockProcessorDslInterface = import("./extensions.js").BlockProcessorDslInterface;
35
+ export type MacroProcessorDslInterface = import("./extensions.js").MacroProcessorDslInterface;
36
+ export type InlineMacroProcessorDslInterface = import("./extensions.js").InlineMacroProcessorDslInterface;
29
37
  import { Document } from './document.js';
30
38
  import { convert } from './convert.js';
31
39
  import { convertFile } from './convert.js';
@@ -1,3 +1,16 @@
1
+
2
+ /**
3
+ * Run fn() within an async-local logger context so that all log calls via
4
+ * `this.logger` (from applyLogging) automatically route to the provided logger
5
+ * for the duration of the async execution chain.
6
+ *
7
+ * Falls back to global mutation in environments without node:async_hooks (e.g. browsers).
8
+ *
9
+ * @param {Logger|MemoryLogger|NullLogger} logger - The logger to activate.
10
+ * @param {() => any} fn - The function to execute within the logger context.
11
+ * @returns {Promise<any>}
12
+ */
13
+ export function withLogger(logger: Logger | MemoryLogger | NullLogger, fn: () => any): Promise<any>;
1
14
  /**
2
15
  * Apply the Logging mixin to a class prototype.
3
16
  *
@@ -120,12 +133,10 @@ export class MemoryLogger {
120
133
  empty(): boolean;
121
134
  }
122
135
  /** Logger that discards all messages but still tracks the maximum severity. */
123
- export class NullLogger {
136
+ export class NullLogger extends Logger {
124
137
  static create(): NullLogger;
138
+ constructor();
125
139
  level: number;
126
- _maxSeverity: number;
127
- get maxSeverity(): number;
128
- getMaxSeverity(): number;
129
140
  add(severity: any): boolean;
130
141
  log(severity: any): boolean;
131
142
  debug(): boolean;