@antora/assembler 1.0.0-beta.3 → 1.0.0-beta.5
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/lib/produce-assembly-file.js +39 -26
- package/package.json +1 -1
|
@@ -371,57 +371,70 @@ function mergeAsciiDoc (
|
|
|
371
371
|
if (~line.indexOf('xref:')) {
|
|
372
372
|
// Q: should we allow : as first character of target?
|
|
373
373
|
line = line.replace(/(?<![\\+])xref:((?:\.\/)?[\p{Alpha}0-9_/.{#].*?)\[(|.*?[^\\])\]/gu, (m, target, text) => {
|
|
374
|
-
let
|
|
374
|
+
let relativePart, fragment, targetResource, isPage
|
|
375
375
|
const hashIdx = target.indexOf('#')
|
|
376
|
+
const dollarIdx = target.indexOf('$')
|
|
376
377
|
if (~hashIdx) {
|
|
377
|
-
|
|
378
|
+
relativePart = target.slice(0, hashIdx)
|
|
378
379
|
fragment = target.slice(hashIdx + 1)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
} else if (target.endsWith('.adoc')) {
|
|
382
|
-
pagePart = target
|
|
380
|
+
} else if (~dollarIdx || target.endsWith('.adoc')) {
|
|
381
|
+
relativePart = target
|
|
383
382
|
fragment = ''
|
|
384
383
|
} else {
|
|
385
384
|
fragment = target
|
|
386
385
|
}
|
|
387
|
-
if (!
|
|
386
|
+
if (!relativePart) {
|
|
388
387
|
// Q: should we validate the internal ID here?
|
|
389
388
|
return text && ~text.indexOf('=')
|
|
390
389
|
? `xref:${idPrefix}${fragment}[${text}]`
|
|
391
390
|
: `<<${idPrefix}${fragment}${text ? ',' + text.replace(/\\]/g, ']') : ''}>>`
|
|
392
391
|
}
|
|
393
|
-
if (~
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
return `${siteUrl}${targetPage.pub.url}${fragment && '#' + fragment}[${text}]`
|
|
392
|
+
if (~dollarIdx) {
|
|
393
|
+
if (relativePart.slice(dollarIdx).startsWith('$./')) {
|
|
394
|
+
relativePart = relativePart.slice(0, dollarIdx + 1) + topicPrefix + relativePart.slice(dollarIdx + 3)
|
|
397
395
|
}
|
|
398
|
-
|
|
396
|
+
if ((isPage = /\bpage\$/.test(relativePart))) relativePart = relativePart.replace('page$', '')
|
|
397
|
+
} else {
|
|
398
|
+
isPage = true
|
|
399
|
+
if (relativePart.startsWith('./')) relativePart = topicPrefix + relativePart.slice(2)
|
|
400
|
+
if (~hashIdx && !relativePart.endsWith('.adoc')) relativePart += '.adoc'
|
|
401
|
+
}
|
|
402
|
+
if (!isPage || ~relativePart.indexOf('@') || /:.*:/.test(relativePart)) {
|
|
403
|
+
if (siteUrl && (targetResource = contentCatalog.resolveResource(relativePart, page.src, 'page'))?.pub) {
|
|
404
|
+
text ||= targetResource.asciidoc?.xreftext || target
|
|
405
|
+
return `${siteUrl}${targetResource.pub.url}${fragment && '#' + fragment}[${text}]`
|
|
406
|
+
}
|
|
407
|
+
// TODO: handle unresolved resource better
|
|
399
408
|
return m
|
|
400
409
|
}
|
|
401
410
|
let targetModule
|
|
402
|
-
const colonIdx =
|
|
411
|
+
const colonIdx = relativePart.indexOf(':')
|
|
403
412
|
if (~colonIdx) {
|
|
404
|
-
targetModule =
|
|
405
|
-
|
|
413
|
+
targetModule = relativePart.slice(0, colonIdx)
|
|
414
|
+
relativePart = relativePart.slice(colonIdx + 1)
|
|
415
|
+
if (relativePart.startsWith('./')) relativePart = topicPrefix + relativePart.slice(2)
|
|
406
416
|
} else {
|
|
407
417
|
targetModule = module_
|
|
408
418
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
419
|
+
const pageResourceRef = targetModule === 'ROOT' ? relativePart : `${targetModule}:${relativePart}`
|
|
420
|
+
if (!(targetResource = pagesInOutline.get(pageResourceRef))) {
|
|
421
|
+
if (
|
|
422
|
+
siteUrl &&
|
|
423
|
+
(targetResource = contentCatalog.resolvePage(pageResourceRef, page.src)) &&
|
|
424
|
+
targetResource.out
|
|
425
|
+
) {
|
|
426
|
+
text ||= targetResource.asciidoc?.xreftext || target
|
|
427
|
+
return `${siteUrl}${targetResource.pub.url}${fragment && '#' + fragment}[${text}]`
|
|
415
428
|
}
|
|
416
429
|
// TODO: handle unresolved page better
|
|
417
430
|
return m
|
|
418
431
|
}
|
|
419
|
-
if (targetModule !== 'ROOT')
|
|
420
|
-
|
|
432
|
+
if (targetModule !== 'ROOT') relativePart = `${targetModule}${idCoordinateSeparator}${relativePart}`
|
|
433
|
+
relativePart = relativePart.replace(/\.adoc$/, '').replace(/[/.]/g, '-')
|
|
421
434
|
const refid = fragment
|
|
422
|
-
? `${
|
|
423
|
-
:
|
|
424
|
-
return `<<${refid}${text && text !==
|
|
435
|
+
? `${relativePart}${idScopeSeparator}${fragment}`
|
|
436
|
+
: relativePart + (ReservedIdNames.includes(relativePart) ? idScopeSeparator : '')
|
|
437
|
+
return `<<${refid}${text && text !== targetResource.title ? ',' + text.replace(/\\]/g, ']') : ''}>>`
|
|
425
438
|
})
|
|
426
439
|
}
|
|
427
440
|
if (~line.indexOf('link:{attachmentsdir}/')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/assembler",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "A JavaScript library that merges AsciiDoc content from multiple pages in an Antora site into assembly files and delegates to an exporter to convert those files to another format, such as PDF.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "OpenDevise Inc. (https://opendevise.com)",
|