@asciidoctor/core 4.0.0-alpha.2 → 4.0.0-alpha.4
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 +649 -131
- package/build/node/index.cjs +652 -131
- package/package.json +3 -2
- package/src/abstract_node.js +8 -13
- package/src/attribute_entry.js +17 -1
- package/src/browser/reader.js +2 -2
- package/src/browser.js +21 -0
- package/src/convert.js +10 -3
- package/src/converter/html5.js +8 -27
- package/src/converter/template.js +1 -1
- package/src/document.js +19 -9
- package/src/extensions.js +266 -8
- package/src/helpers.js +20 -2
- package/src/http_cache.js +139 -0
- package/src/index.js +16 -0
- package/src/load.js +30 -13
- package/src/logging.js +65 -5
- package/src/parser.js +1 -1
- package/src/path_resolver.js +20 -15
- package/src/reader.js +3 -2
- package/src/stylesheets.js +15 -0
- package/types/abstract_node.d.ts +1 -2
- package/types/attribute_entry.d.ts +8 -0
- package/types/browser/reader.d.ts +1 -1
- package/types/extensions.d.ts +203 -9
- package/types/http_cache.d.ts +59 -0
- package/types/index.d.cts +12 -1
- package/types/index.d.ts +12 -1
- package/types/logging.d.ts +15 -4
- package/types/path_resolver.d.ts +0 -5
- package/types/stylesheets.d.ts +1 -0
- package/types/table.d.ts +1 -1
package/src/logging.js
CHANGED
|
@@ -39,6 +39,65 @@ function resolveSeverity(severity) {
|
|
|
39
39
|
return severity ?? Severity.UNKNOWN
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// ── Per-execution logger context ─────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
// Holds an AsyncLocalStorage instance once it is lazily initialised.
|
|
45
|
+
// Allows per-execution logger isolation without mutating the global singleton,
|
|
46
|
+
// making concurrent test execution (e.g. Deno's node:test) safe.
|
|
47
|
+
let _loggerStore = null
|
|
48
|
+
|
|
49
|
+
// Promise singleton — ensures AsyncLocalStorage is initialised at most once.
|
|
50
|
+
let _loggerStorePromise = null
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Lazily initialise an AsyncLocalStorage for per-execution logger context.
|
|
54
|
+
* Falls back to null in environments that do not support node:async_hooks (e.g. browsers).
|
|
55
|
+
* @returns {Promise<import('node:async_hooks').AsyncLocalStorage|null>}
|
|
56
|
+
*/
|
|
57
|
+
async function _ensureLoggerStore() {
|
|
58
|
+
if (_loggerStorePromise === null) {
|
|
59
|
+
_loggerStorePromise = import('node:async_hooks')
|
|
60
|
+
.then(({ AsyncLocalStorage }) => {
|
|
61
|
+
const store = new AsyncLocalStorage()
|
|
62
|
+
_loggerStore = store
|
|
63
|
+
return store
|
|
64
|
+
})
|
|
65
|
+
.catch(() => null)
|
|
66
|
+
}
|
|
67
|
+
return _loggerStorePromise
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @internal — returns the logger bound to the current async context, or null */
|
|
71
|
+
export function getContextLogger() {
|
|
72
|
+
return _loggerStore?.getStore() ?? null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Run fn() within an async-local logger context so that all log calls via
|
|
77
|
+
* `this.logger` (from applyLogging) automatically route to the provided logger
|
|
78
|
+
* for the duration of the async execution chain.
|
|
79
|
+
*
|
|
80
|
+
* Falls back to global mutation in environments without node:async_hooks (e.g. browsers).
|
|
81
|
+
*
|
|
82
|
+
* @param {Logger|MemoryLogger|NullLogger} logger - The logger to activate.
|
|
83
|
+
* @param {() => any} fn - The function to execute within the logger context.
|
|
84
|
+
* @returns {Promise<any>}
|
|
85
|
+
*/
|
|
86
|
+
export async function withLogger(logger, fn) {
|
|
87
|
+
const store = await _ensureLoggerStore()
|
|
88
|
+
if (store) {
|
|
89
|
+
return store.run(logger, fn)
|
|
90
|
+
}
|
|
91
|
+
// Fallback for environments without node:async_hooks (browsers).
|
|
92
|
+
const prev = LoggerManager.logger
|
|
93
|
+
if (logger !== prev) LoggerManager.logger = logger
|
|
94
|
+
try {
|
|
95
|
+
return await fn()
|
|
96
|
+
} finally {
|
|
97
|
+
if (logger !== prev) LoggerManager.logger = prev
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
42
101
|
// ── Logger ────────────────────────────────────────────────────────────────────
|
|
43
102
|
|
|
44
103
|
/** Standard logger that writes formatted messages to stderr or a custom pipe. */
|
|
@@ -347,8 +406,9 @@ export class MemoryLogger {
|
|
|
347
406
|
// ── NullLogger ────────────────────────────────────────────────────────────────
|
|
348
407
|
|
|
349
408
|
/** Logger that discards all messages but still tracks the maximum severity. */
|
|
350
|
-
export class NullLogger {
|
|
409
|
+
export class NullLogger extends Logger {
|
|
351
410
|
constructor() {
|
|
411
|
+
super()
|
|
352
412
|
this.level = Severity.UNKNOWN
|
|
353
413
|
this._maxSeverity = null
|
|
354
414
|
}
|
|
@@ -493,12 +553,12 @@ export const LoggerManager = (() => {
|
|
|
493
553
|
export function applyLogging(proto) {
|
|
494
554
|
Object.defineProperty(proto, 'logger', {
|
|
495
555
|
get() {
|
|
496
|
-
return LoggerManager.logger
|
|
556
|
+
return _loggerStore?.getStore() ?? LoggerManager.logger
|
|
497
557
|
},
|
|
498
558
|
configurable: true,
|
|
499
559
|
})
|
|
500
560
|
|
|
501
|
-
proto.getLogger = () => LoggerManager.logger
|
|
561
|
+
proto.getLogger = () => _loggerStore?.getStore() ?? LoggerManager.logger
|
|
502
562
|
|
|
503
563
|
proto.messageWithContext = (text, context = {}) =>
|
|
504
564
|
Logger.AutoFormattingMessage.attach({ text, ...context })
|
|
@@ -512,10 +572,10 @@ export function applyLogging(proto) {
|
|
|
512
572
|
*/
|
|
513
573
|
export const Logging = {
|
|
514
574
|
get logger() {
|
|
515
|
-
return LoggerManager.logger
|
|
575
|
+
return _loggerStore?.getStore() ?? LoggerManager.logger
|
|
516
576
|
},
|
|
517
577
|
getLogger() {
|
|
518
|
-
return LoggerManager.logger
|
|
578
|
+
return _loggerStore?.getStore() ?? LoggerManager.logger
|
|
519
579
|
},
|
|
520
580
|
messageWithContext(text, context = {}) {
|
|
521
581
|
return Logger.AutoFormattingMessage.attach({ text, ...context })
|
package/src/parser.js
CHANGED
|
@@ -1549,7 +1549,7 @@ export class Parser {
|
|
|
1549
1549
|
const Rdr = Reader
|
|
1550
1550
|
const result = await extension.processMethod(
|
|
1551
1551
|
parent,
|
|
1552
|
-
blockReader ?? new Rdr(lines),
|
|
1552
|
+
blockReader ?? new Rdr(lines, null, { document: parent.document }),
|
|
1553
1553
|
{ ...attributes }
|
|
1554
1554
|
)
|
|
1555
1555
|
if (!result || result === parent) return null
|
package/src/path_resolver.js
CHANGED
|
@@ -123,14 +123,6 @@ export class PathResolver {
|
|
|
123
123
|
: path
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
/**
|
|
127
|
-
* @param {string} path
|
|
128
|
-
* @returns {string}
|
|
129
|
-
*/
|
|
130
|
-
posixfy(path) {
|
|
131
|
-
return this.posixify(path)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
126
|
/**
|
|
135
127
|
* Expand the path by resolving parent references (..) and removing self references (.).
|
|
136
128
|
* @param {string} path
|
|
@@ -431,14 +423,27 @@ function _platformSeparator() {
|
|
|
431
423
|
* @internal
|
|
432
424
|
*/
|
|
433
425
|
function _expandPath(p) {
|
|
434
|
-
if (typeof process
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
426
|
+
if (typeof process === 'undefined') return p
|
|
427
|
+
const cwd = process.cwd().replace(/\\/g, '/')
|
|
428
|
+
const full = `${cwd}/${p.replace(/\\/g, '/')}`
|
|
429
|
+
let root, rest
|
|
430
|
+
if (full.startsWith('//')) {
|
|
431
|
+
root = '//'
|
|
432
|
+
rest = full.slice(2)
|
|
433
|
+
} else if (full.startsWith('/')) {
|
|
434
|
+
root = '/'
|
|
435
|
+
rest = full.slice(1)
|
|
436
|
+
} else {
|
|
437
|
+
const slash = full.indexOf('/')
|
|
438
|
+
root = full.slice(0, slash + 1)
|
|
439
|
+
rest = full.slice(slash + 1)
|
|
440
|
+
}
|
|
441
|
+
const resolved = []
|
|
442
|
+
for (const seg of rest.split('/')) {
|
|
443
|
+
if (seg === '..') resolved.pop()
|
|
444
|
+
else if (seg && seg !== '.') resolved.push(seg)
|
|
440
445
|
}
|
|
441
|
-
return
|
|
446
|
+
return root + resolved.join('/')
|
|
442
447
|
}
|
|
443
448
|
|
|
444
449
|
/**
|
package/src/reader.js
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
isUriish,
|
|
43
43
|
} from './helpers.js'
|
|
44
44
|
import { LoggerManager, Logger } from './logging.js'
|
|
45
|
+
import { fetchUri } from './http_cache.js'
|
|
45
46
|
import { Compliance } from './compliance.js'
|
|
46
47
|
import { resolveBrowserIncludePath } from './browser/reader.js'
|
|
47
48
|
|
|
@@ -661,7 +662,7 @@ export class Reader {
|
|
|
661
662
|
return this.source()
|
|
662
663
|
}
|
|
663
664
|
getLogger() {
|
|
664
|
-
return LoggerManager.logger
|
|
665
|
+
return this._document?.logger ?? LoggerManager.logger
|
|
665
666
|
}
|
|
666
667
|
createLogMessage(text, context = {}) {
|
|
667
668
|
return Logger.AutoFormattingMessage.attach({ text, ...context })
|
|
@@ -1309,7 +1310,7 @@ export class PreprocessorReader extends Reader {
|
|
|
1309
1310
|
if (targetType === 'uri') {
|
|
1310
1311
|
let uriContent
|
|
1311
1312
|
try {
|
|
1312
|
-
const response = await
|
|
1313
|
+
const response = await fetchUri(incPath, this._document)
|
|
1313
1314
|
if (!response.ok)
|
|
1314
1315
|
throw new Error(`HTTP ${response.status} ${response.statusText}`)
|
|
1315
1316
|
uriContent = await response.text()
|
package/src/stylesheets.js
CHANGED
|
@@ -23,6 +23,21 @@ class StylesheetsClass {
|
|
|
23
23
|
async embedPrimaryStylesheet() {
|
|
24
24
|
return `<style>\n${defaultStylesheetData}\n</style>`
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
async writePrimaryStylesheet(stylesoutdir) {
|
|
28
|
+
try {
|
|
29
|
+
const { writeFile } = await import('node:fs/promises')
|
|
30
|
+
const { join } = await import('node:path')
|
|
31
|
+
await writeFile(
|
|
32
|
+
join(stylesoutdir, StylesheetsClass.DEFAULT_STYLESHEET_NAME),
|
|
33
|
+
defaultStylesheetData,
|
|
34
|
+
'utf8'
|
|
35
|
+
)
|
|
36
|
+
return true
|
|
37
|
+
} catch {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
}
|
|
26
41
|
}
|
|
27
42
|
|
|
28
43
|
export const Stylesheets = {
|
package/types/abstract_node.d.ts
CHANGED
|
@@ -278,10 +278,9 @@ export abstract class AbstractNode {
|
|
|
278
278
|
* imageUri, the caller must await the returned Promise.
|
|
279
279
|
*
|
|
280
280
|
* @param {string} imageUri - The URI from which to read the image data (http/https/ftp).
|
|
281
|
-
* @param {boolean} [cacheUri=false] - A Boolean to control caching (not yet supported in JS).
|
|
282
281
|
* @returns {Promise<string>} a Promise resolving to a String data URI.
|
|
283
282
|
*/
|
|
284
|
-
generateDataUriFromUri(imageUri: string
|
|
283
|
+
generateDataUriFromUri(imageUri: string): Promise<string>;
|
|
285
284
|
/**
|
|
286
285
|
* Normalize the asset file or directory to a concrete and rinsed path.
|
|
287
286
|
*
|
|
@@ -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
|
|
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
|
*
|
package/types/extensions.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
286
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch a URI, routing through the HTTP cache when `cache-uri` is set on the document.
|
|
3
|
+
* @param {string} uri
|
|
4
|
+
* @param {object} doc - the current Document instance
|
|
5
|
+
* @returns {Promise<Response>}
|
|
6
|
+
*/
|
|
7
|
+
export function fetchUri(uri: string, doc: object): Promise<Response>;
|
|
8
|
+
/**
|
|
9
|
+
* Base HTTP cache class.
|
|
10
|
+
*
|
|
11
|
+
* The default implementation delegates directly to fetch() with no caching.
|
|
12
|
+
* Subclasses override read() to add caching behaviour.
|
|
13
|
+
*/
|
|
14
|
+
export class HttpCache {
|
|
15
|
+
/**
|
|
16
|
+
* Fetch content from a URI, optionally from a cache.
|
|
17
|
+
* @param {string} uri
|
|
18
|
+
* @returns {Promise<Response>}
|
|
19
|
+
*/
|
|
20
|
+
read(uri: string): Promise<Response>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* In-memory HTTP cache.
|
|
24
|
+
*
|
|
25
|
+
* Stores successful responses as ArrayBuffers keyed by URI. On a cache hit
|
|
26
|
+
* a synthetic Response is reconstructed from the stored data without touching
|
|
27
|
+
* the network. Non-OK responses (4xx, 5xx) are never cached.
|
|
28
|
+
*
|
|
29
|
+
* Safe as an ephemeral per-conversion cache or as a longer-lived process-level
|
|
30
|
+
* cache when registered via HttpCacheManager.setCache().
|
|
31
|
+
*/
|
|
32
|
+
export class MemoryHttpCache extends HttpCache {
|
|
33
|
+
read(uri: any): Promise<any>;
|
|
34
|
+
#private;
|
|
35
|
+
}
|
|
36
|
+
export namespace HttpCacheManager {
|
|
37
|
+
/** @type {HttpCache|null} */
|
|
38
|
+
let _cache: HttpCache | null;
|
|
39
|
+
/**
|
|
40
|
+
* Register a cache to use for all conversions.
|
|
41
|
+
* Pass null to unregister and revert to the ephemeral default.
|
|
42
|
+
* @param {HttpCache|null} cache
|
|
43
|
+
*/
|
|
44
|
+
function setCache(cache: HttpCache | null): void;
|
|
45
|
+
/**
|
|
46
|
+
* Return the registered process-level cache, or null if none is registered.
|
|
47
|
+
* @returns {HttpCache|null}
|
|
48
|
+
*/
|
|
49
|
+
function getCache(): HttpCache | null;
|
|
50
|
+
/**
|
|
51
|
+
* Return the cache to use for a specific document conversion.
|
|
52
|
+
*
|
|
53
|
+
* Returns the registered cache if one exists; otherwise creates (or reuses)
|
|
54
|
+
* an ephemeral MemoryHttpCache scoped to the document's lifetime via a WeakMap.
|
|
55
|
+
* @param {object} doc - the current Document instance
|
|
56
|
+
* @returns {HttpCache}
|
|
57
|
+
*/
|
|
58
|
+
function getCacheForDocument(doc: object): HttpCache;
|
|
59
|
+
}
|
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';
|
|
@@ -48,6 +56,9 @@ import { SyntaxHighlighterBase } from './syntax_highlighter.js';
|
|
|
48
56
|
import { LoggerManager } from './logging.js';
|
|
49
57
|
import { MemoryLogger } from './logging.js';
|
|
50
58
|
import { NullLogger } from './logging.js';
|
|
59
|
+
import { HttpCache } from './http_cache.js';
|
|
60
|
+
import { MemoryHttpCache } from './http_cache.js';
|
|
61
|
+
import { HttpCacheManager } from './http_cache.js';
|
|
51
62
|
import { SafeMode } from './constants.js';
|
|
52
63
|
import { ContentModel } from './constants.js';
|
|
53
64
|
import { Timings } from './timings.js';
|
|
@@ -72,4 +83,4 @@ import { deriveBackendTraits } from './converter.js';
|
|
|
72
83
|
import { DefaultFactory as DefaultSyntaxHighlighterFactory } from './syntax_highlighter.js';
|
|
73
84
|
import Html5Converter from './converter/html5.js';
|
|
74
85
|
import { SyntaxHighlighter } from './syntax_highlighter.js';
|
|
75
|
-
export { convert, convertFile, Document, DocumentTitle, Author, Footnote, ImageReference, RevisionInfo, Logger, AbstractNode, AbstractBlock, Inline, Block, List, ListItem, Section, Reader, SyntaxHighlighterBase, LoggerManager, MemoryLogger, NullLogger, SafeMode, ContentModel, Timings, Registry, Processor, ProcessorExtension, Preprocessor, TreeProcessor, Postprocessor, IncludeProcessor, DocinfoProcessor, BlockProcessor, InlineMacroProcessor, BlockMacroProcessor, Extensions, Cursor, Converter as ConverterFactory, ConverterBase, CustomFactory as ConverterCustomFactory, DefaultConverterFactory, deriveBackendTraits, DefaultSyntaxHighlighterFactory, Html5Converter, SyntaxHighlighter };
|
|
86
|
+
export { convert, convertFile, Document, DocumentTitle, Author, Footnote, ImageReference, RevisionInfo, Logger, AbstractNode, AbstractBlock, Inline, Block, List, ListItem, Section, Reader, SyntaxHighlighterBase, LoggerManager, MemoryLogger, NullLogger, HttpCache, MemoryHttpCache, HttpCacheManager, SafeMode, ContentModel, Timings, Registry, Processor, ProcessorExtension, Preprocessor, TreeProcessor, Postprocessor, IncludeProcessor, DocinfoProcessor, BlockProcessor, InlineMacroProcessor, BlockMacroProcessor, Extensions, Cursor, Converter as ConverterFactory, ConverterBase, CustomFactory as ConverterCustomFactory, DefaultConverterFactory, deriveBackendTraits, DefaultSyntaxHighlighterFactory, Html5Converter, SyntaxHighlighter };
|