@asciidoctor/core 4.0.2 → 4.0.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/build/browser/index.js +148 -6
- package/build/node/index.cjs +148 -6
- package/package.json +2 -1
- package/src/document.js +4 -0
- package/src/extensions.js +143 -5
- package/src/index.js +4 -0
- package/types/extensions.d.ts +390 -14
- package/types/index.d.cts +4 -0
- package/types/index.d.ts +4 -0
package/src/extensions.js
CHANGED
|
@@ -54,6 +54,30 @@ import { MacroNameRx, CC_ANY } from './rx.js'
|
|
|
54
54
|
* @typedef {ProcessorDslInterface & { prefer(): void; prepend(): void }} DocumentProcessorDslInterface
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* DSL interface for preprocessors.
|
|
59
|
+
*
|
|
60
|
+
* @typedef {Omit<DocumentProcessorDslInterface, 'process'> & {
|
|
61
|
+
* process(fn: (this: PreprocessorDslInterface, document: Document, reader: Reader) => Reader | void): void;
|
|
62
|
+
* }} PreprocessorDslInterface
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* DSL interface for tree processors.
|
|
67
|
+
*
|
|
68
|
+
* @typedef {Omit<DocumentProcessorDslInterface, 'process'> & {
|
|
69
|
+
* process(fn: (this: TreeProcessorDslInterface, document: Document) => Document | void): void;
|
|
70
|
+
* }} TreeProcessorDslInterface
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* DSL interface for postprocessors.
|
|
75
|
+
*
|
|
76
|
+
* @typedef {Omit<DocumentProcessorDslInterface, 'process'> & {
|
|
77
|
+
* process(fn: (this: PostprocessorDslInterface, document: Document, output: string) => string): void;
|
|
78
|
+
* }} PostprocessorDslInterface
|
|
79
|
+
*/
|
|
80
|
+
|
|
57
81
|
/**
|
|
58
82
|
* DSL interface for syntax processors (BlockProcessor, BlockMacroProcessor, InlineMacroProcessor).
|
|
59
83
|
*
|
|
@@ -74,28 +98,35 @@ import { MacroNameRx, CC_ANY } from './rx.js'
|
|
|
74
98
|
/**
|
|
75
99
|
* DSL interface for include processors.
|
|
76
100
|
*
|
|
77
|
-
* @typedef {DocumentProcessorDslInterface & {
|
|
101
|
+
* @typedef {Omit<DocumentProcessorDslInterface, 'process'> & {
|
|
78
102
|
* handles(fn: (target: string) => boolean): void;
|
|
79
103
|
* handles(fn: (doc: Document, target: string) => boolean): void;
|
|
104
|
+
* process(fn: (this: IncludeProcessorDslInterface, document: Document, reader: Reader, target: string, attributes: Record<string, string>) => void): void;
|
|
80
105
|
* }} IncludeProcessorDslInterface
|
|
81
106
|
*/
|
|
82
107
|
|
|
83
108
|
/**
|
|
84
109
|
* DSL interface for docinfo processors.
|
|
85
110
|
*
|
|
86
|
-
* @typedef {DocumentProcessorDslInterface & {
|
|
111
|
+
* @typedef {Omit<DocumentProcessorDslInterface, 'process'> & {
|
|
87
112
|
* atLocation(value: string): void;
|
|
113
|
+
* process(fn: (this: DocinfoProcessorDslInterface, document: Document) => string): void;
|
|
88
114
|
* }} DocinfoProcessorDslInterface
|
|
89
115
|
*/
|
|
90
116
|
|
|
91
117
|
/**
|
|
92
118
|
* DSL interface for block processors.
|
|
93
119
|
*
|
|
94
|
-
*
|
|
120
|
+
* The `process` callback is bound to the processor instance, so `this` inside it
|
|
121
|
+
* (and inside the registration function) exposes the `createBlock` helpers.
|
|
122
|
+
*
|
|
123
|
+
* @typedef {Omit<SyntaxProcessorDslInterface, 'process'> & {
|
|
95
124
|
* contexts(...value: (string | string[])[]): void;
|
|
96
125
|
* onContexts(...value: (string | string[])[]): void;
|
|
97
126
|
* onContext(...value: (string | string[])[]): void;
|
|
98
127
|
* bindTo(...value: (string | string[])[]): void;
|
|
128
|
+
* createBlock(parent: AbstractBlock, context: string, source?: string | string[] | null, attrs?: object, opts?: object): Block;
|
|
129
|
+
* process(fn: (this: BlockProcessorDslInterface, parent: AbstractBlock, reader: Reader, attributes: Record<string, unknown>) => AbstractBlock | void): void;
|
|
99
130
|
* }} BlockProcessorDslInterface
|
|
100
131
|
*/
|
|
101
132
|
|
|
@@ -105,14 +136,31 @@ import { MacroNameRx, CC_ANY } from './rx.js'
|
|
|
105
136
|
* @typedef {SyntaxProcessorDslInterface} MacroProcessorDslInterface
|
|
106
137
|
*/
|
|
107
138
|
|
|
139
|
+
/**
|
|
140
|
+
* DSL interface for block macro processors.
|
|
141
|
+
*
|
|
142
|
+
* The `process` callback is bound to the processor instance, so `this` inside it
|
|
143
|
+
* (and inside the registration function) exposes the `createBlock` helpers.
|
|
144
|
+
*
|
|
145
|
+
* @typedef {Omit<MacroProcessorDslInterface, 'process'> & {
|
|
146
|
+
* createBlock(parent: AbstractBlock, context: string, source?: string | string[] | null, attrs?: object, opts?: object): Block;
|
|
147
|
+
* process(fn: (this: BlockMacroProcessorDslInterface, parent: AbstractBlock, target: string, attributes: Record<string, unknown>) => AbstractBlock | void): void;
|
|
148
|
+
* }} BlockMacroProcessorDslInterface
|
|
149
|
+
*/
|
|
150
|
+
|
|
108
151
|
/**
|
|
109
152
|
* DSL interface for inline macro processors.
|
|
110
153
|
*
|
|
111
|
-
*
|
|
154
|
+
* The `process` callback is bound to the processor instance, so `this` inside it
|
|
155
|
+
* (and inside the registration function) exposes the `createInline` helper.
|
|
156
|
+
*
|
|
157
|
+
* @typedef {Omit<MacroProcessorDslInterface, 'process'> & {
|
|
112
158
|
* format(value: string): void;
|
|
113
159
|
* matchFormat(value: string): void;
|
|
114
160
|
* usingFormat(value: string): void;
|
|
115
161
|
* match(value: RegExp): void;
|
|
162
|
+
* createInline(parent: AbstractBlock, context: string, text: string, opts?: object): Inline;
|
|
163
|
+
* process(fn: (this: InlineMacroProcessorDslInterface, parent: AbstractBlock, target: string, attributes: Record<string, unknown>) => Inline | void): void;
|
|
116
164
|
* }} InlineMacroProcessorDslInterface
|
|
117
165
|
*/
|
|
118
166
|
|
|
@@ -839,7 +887,15 @@ export class IncludeProcessor extends Processor {
|
|
|
839
887
|
}
|
|
840
888
|
|
|
841
889
|
/**
|
|
842
|
-
*
|
|
890
|
+
* Decide whether this include processor handles the given target.
|
|
891
|
+
*
|
|
892
|
+
* Override this method in a subclass. The override may accept either just the
|
|
893
|
+
* target string (Ruby-style, arity 1) or both the document and the target
|
|
894
|
+
* (arity 2) — an arity-1 override is adapted at registration time so the
|
|
895
|
+
* parser can always invoke it as `handles(doc, target)`. The first parameter
|
|
896
|
+
* is therefore typed `Document | string` so both override shapes type-check.
|
|
897
|
+
*
|
|
898
|
+
* @param {Document|string} doc - The document being parsed, or (for a Ruby-style arity-1 override) the include target.
|
|
843
899
|
* @param {string} target - The target of the include directive.
|
|
844
900
|
* @returns {boolean} true if this processor handles the given target.
|
|
845
901
|
*/
|
|
@@ -1251,6 +1307,14 @@ export class Registry {
|
|
|
1251
1307
|
* this.process(function (doc, reader) { ... })
|
|
1252
1308
|
* })
|
|
1253
1309
|
*
|
|
1310
|
+
* @overload
|
|
1311
|
+
* @param {typeof Preprocessor} processor - A Preprocessor subclass or instance.
|
|
1312
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1313
|
+
*
|
|
1314
|
+
* @overload
|
|
1315
|
+
* @param {(this: PreprocessorDslInterface) => void} fn - Registration function bound to the preprocessor DSL.
|
|
1316
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1317
|
+
*
|
|
1254
1318
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1255
1319
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1256
1320
|
*/
|
|
@@ -1284,6 +1348,14 @@ export class Registry {
|
|
|
1284
1348
|
/**
|
|
1285
1349
|
* Register a TreeProcessor with the extension registry.
|
|
1286
1350
|
*
|
|
1351
|
+
* @overload
|
|
1352
|
+
* @param {typeof TreeProcessor} processor - A TreeProcessor subclass or instance.
|
|
1353
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1354
|
+
*
|
|
1355
|
+
* @overload
|
|
1356
|
+
* @param {(this: TreeProcessorDslInterface) => void} fn - Registration function bound to the tree processor DSL.
|
|
1357
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1358
|
+
*
|
|
1287
1359
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1288
1360
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1289
1361
|
*/
|
|
@@ -1337,6 +1409,14 @@ export class Registry {
|
|
|
1337
1409
|
/**
|
|
1338
1410
|
* Register a Postprocessor with the extension registry.
|
|
1339
1411
|
*
|
|
1412
|
+
* @overload
|
|
1413
|
+
* @param {typeof Postprocessor} processor - A Postprocessor subclass or instance.
|
|
1414
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1415
|
+
*
|
|
1416
|
+
* @overload
|
|
1417
|
+
* @param {(this: PostprocessorDslInterface) => void} fn - Registration function bound to the postprocessor DSL.
|
|
1418
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1419
|
+
*
|
|
1340
1420
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1341
1421
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1342
1422
|
*/
|
|
@@ -1370,6 +1450,14 @@ export class Registry {
|
|
|
1370
1450
|
/**
|
|
1371
1451
|
* Register an IncludeProcessor with the extension registry.
|
|
1372
1452
|
*
|
|
1453
|
+
* @overload
|
|
1454
|
+
* @param {typeof IncludeProcessor} processor - An IncludeProcessor subclass or instance.
|
|
1455
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1456
|
+
*
|
|
1457
|
+
* @overload
|
|
1458
|
+
* @param {(this: IncludeProcessorDslInterface) => void} fn - Registration function bound to the include processor DSL.
|
|
1459
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1460
|
+
*
|
|
1373
1461
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1374
1462
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1375
1463
|
*/
|
|
@@ -1408,6 +1496,14 @@ export class Registry {
|
|
|
1408
1496
|
/**
|
|
1409
1497
|
* Register a DocinfoProcessor with the extension registry.
|
|
1410
1498
|
*
|
|
1499
|
+
* @overload
|
|
1500
|
+
* @param {typeof DocinfoProcessor} processor - A DocinfoProcessor subclass or instance.
|
|
1501
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1502
|
+
*
|
|
1503
|
+
* @overload
|
|
1504
|
+
* @param {(this: DocinfoProcessorDslInterface) => void} fn - Registration function bound to the docinfo processor DSL.
|
|
1505
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1506
|
+
*
|
|
1411
1507
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1412
1508
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1413
1509
|
*/
|
|
@@ -1475,6 +1571,20 @@ export class Registry {
|
|
|
1475
1571
|
* this.process(function (parent, reader, attrs) { ... })
|
|
1476
1572
|
* })
|
|
1477
1573
|
*
|
|
1574
|
+
* @overload
|
|
1575
|
+
* @param {typeof BlockProcessor} processor - A BlockProcessor subclass.
|
|
1576
|
+
* @param {string} [name] - Optional explicit block name.
|
|
1577
|
+
* @returns {ProcessorExtension} an Extension proxy object.
|
|
1578
|
+
*
|
|
1579
|
+
* @overload
|
|
1580
|
+
* @param {string} name - The block name.
|
|
1581
|
+
* @param {(this: BlockProcessorDslInterface) => void} fn - Registration function bound to the block DSL.
|
|
1582
|
+
* @returns {ProcessorExtension} an Extension proxy object.
|
|
1583
|
+
*
|
|
1584
|
+
* @overload
|
|
1585
|
+
* @param {(this: BlockProcessorDslInterface) => void} fn - Registration function bound to the block DSL.
|
|
1586
|
+
* @returns {ProcessorExtension} an Extension proxy object.
|
|
1587
|
+
*
|
|
1478
1588
|
* @param {...*} args - Class constructor, instance, block function, or name + one of those.
|
|
1479
1589
|
* @returns {ProcessorExtension} an Extension proxy object.
|
|
1480
1590
|
*/
|
|
@@ -1525,6 +1635,20 @@ export class Registry {
|
|
|
1525
1635
|
/**
|
|
1526
1636
|
* Register a BlockMacroProcessor with the extension registry.
|
|
1527
1637
|
*
|
|
1638
|
+
* @overload
|
|
1639
|
+
* @param {typeof BlockMacroProcessor} processor - A BlockMacroProcessor subclass.
|
|
1640
|
+
* @param {string} [name] - Optional explicit macro name.
|
|
1641
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1642
|
+
*
|
|
1643
|
+
* @overload
|
|
1644
|
+
* @param {string} name - The macro name.
|
|
1645
|
+
* @param {(this: BlockMacroProcessorDslInterface) => void} fn - Registration function bound to the block macro DSL.
|
|
1646
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1647
|
+
*
|
|
1648
|
+
* @overload
|
|
1649
|
+
* @param {(this: BlockMacroProcessorDslInterface) => void} fn - Registration function bound to the block macro DSL.
|
|
1650
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1651
|
+
*
|
|
1528
1652
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1529
1653
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1530
1654
|
*/
|
|
@@ -1580,6 +1704,20 @@ export class Registry {
|
|
|
1580
1704
|
/**
|
|
1581
1705
|
* Register an InlineMacroProcessor with the extension registry.
|
|
1582
1706
|
*
|
|
1707
|
+
* @overload
|
|
1708
|
+
* @param {typeof InlineMacroProcessor} processor - An InlineMacroProcessor subclass.
|
|
1709
|
+
* @param {string} [name] - Optional explicit macro name.
|
|
1710
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1711
|
+
*
|
|
1712
|
+
* @overload
|
|
1713
|
+
* @param {string} name - The macro name.
|
|
1714
|
+
* @param {(this: InlineMacroProcessorDslInterface) => void} fn - Registration function bound to the inline macro DSL.
|
|
1715
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1716
|
+
*
|
|
1717
|
+
* @overload
|
|
1718
|
+
* @param {(this: InlineMacroProcessorDslInterface) => void} fn - Registration function bound to the inline macro DSL.
|
|
1719
|
+
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1720
|
+
*
|
|
1583
1721
|
* @param {...*} args - Class constructor, instance, or block function.
|
|
1584
1722
|
* @returns {ProcessorExtension} the Extension stored in the registry.
|
|
1585
1723
|
*/
|
package/src/index.js
CHANGED
|
@@ -40,11 +40,15 @@ import {
|
|
|
40
40
|
/**
|
|
41
41
|
* @typedef {import('./extensions.js').ProcessorDslInterface} ProcessorDslInterface
|
|
42
42
|
* @typedef {import('./extensions.js').DocumentProcessorDslInterface} DocumentProcessorDslInterface
|
|
43
|
+
* @typedef {import('./extensions.js').PreprocessorDslInterface} PreprocessorDslInterface
|
|
44
|
+
* @typedef {import('./extensions.js').TreeProcessorDslInterface} TreeProcessorDslInterface
|
|
45
|
+
* @typedef {import('./extensions.js').PostprocessorDslInterface} PostprocessorDslInterface
|
|
43
46
|
* @typedef {import('./extensions.js').SyntaxProcessorDslInterface} SyntaxProcessorDslInterface
|
|
44
47
|
* @typedef {import('./extensions.js').IncludeProcessorDslInterface} IncludeProcessorDslInterface
|
|
45
48
|
* @typedef {import('./extensions.js').DocinfoProcessorDslInterface} DocinfoProcessorDslInterface
|
|
46
49
|
* @typedef {import('./extensions.js').BlockProcessorDslInterface} BlockProcessorDslInterface
|
|
47
50
|
* @typedef {import('./extensions.js').MacroProcessorDslInterface} MacroProcessorDslInterface
|
|
51
|
+
* @typedef {import('./extensions.js').BlockMacroProcessorDslInterface} BlockMacroProcessorDslInterface
|
|
48
52
|
* @typedef {import('./extensions.js').InlineMacroProcessorDslInterface} InlineMacroProcessorDslInterface
|
|
49
53
|
*/
|
|
50
54
|
import {
|