@antora/assembler 1.0.0-beta.15 → 1.0.0-beta.16

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.
@@ -318,6 +318,10 @@ function mergeAsciiDoc (
318
318
  }
319
319
  }
320
320
  const refs = doc.getCatalog().refs
321
+ const scannedInlineAnchors = Object.values(refs.$$smap).reduce((accum, it) => {
322
+ if (it.node_name === 'inline_anchor') accum[it.id] = it
323
+ return accum
324
+ }, {})
321
325
  allBlocks.forEach((block) => {
322
326
  const contentModel = block.content_model
323
327
  if (
@@ -376,16 +380,22 @@ function mergeAsciiDoc (
376
380
  if (!refs['$key?'](refid) && (~refid.indexOf(' ') || refid.toLowerCase() !== refid)) {
377
381
  if ((refid = doc.$resolve_id(refid))['$nil?']()) return m
378
382
  }
379
- return `<<${idPrefix}${refid}${text ? ',' + text : ''}>>`
383
+ const alphaPrefix = !(refid in scannedInlineAnchors) || /^[\p{Alpha}_:]/u.test(idPrefix) ? '' : 'iid-'
384
+ return `<<${alphaPrefix}${idPrefix}${refid}${text ? ',' + text : ''}>>`
380
385
  })
381
386
  }
382
387
  // NOTE: the next check takes care of inline and block anchors
383
388
  if (~line.indexOf('[[')) {
384
- line = line.replace(/\[\[([\p{Alpha}_:][\p{Alpha}0-9_\-:.]*)(|, *.+?)\]\]/gu, `[[${idPrefix}$1$2]]`)
389
+ line = line.replace(/\[\[([\p{Alpha}_:][\p{Alpha}0-9_\-:.]*)(|, *.+?)\]\]/gu, (m, refid, text) => {
390
+ const alphaPrefix = !(refid in scannedInlineAnchors) || /^[\p{Alpha}_:]/u.test(idPrefix) ? '' : 'iid-'
391
+ return `[[${alphaPrefix}${idPrefix}${refid}${text}]]`
392
+ })
385
393
  }
386
394
  if (~line.indexOf('xref:')) {
387
395
  // Q: should we allow : as first character of target?
388
- line = line.replace(/(?<![\\+])xref:((?:\.\/)?[\p{Alpha}0-9_/.{#].*?)\[(|.*?[^\\])\]/gu, (_, target, text) => {
396
+ line = line.replace(/(?<![\\+])xref:((?:\.\/)?[\p{Alpha}0-9_/.{#].*?)\[(|.*?[^\\])\]/gu, (_, target_, text) => {
397
+ let target = target_
398
+ if (~target.indexOf('{')) target = doc.$sub_attributes(target, Opal.hash({ attribute_missing: 'skip' }))
389
399
  let fragment, resource, resourceRef
390
400
  const hashIdx = target.indexOf('#')
391
401
  if (~hashIdx) {
@@ -402,21 +412,21 @@ function mergeAsciiDoc (
402
412
  const resourceId = parseResourceRef(resourceRef, page.src, 'page', contentCatalog)
403
413
  if (resourceId.family !== 'page' || !(resource = pagesInOutline.get(createResourceKey(resourceId)))) {
404
414
  if ((resource = contentCatalog.getById(resourceId))?.pub) {
405
- text ||= resource.asciidoc?.xreftext || target
415
+ text ||= resource.asciidoc?.xreftext || target_
406
416
  if (siteRoot || linkRefStyle === 'relative') {
407
417
  return `${resolveLinkTarget(resource, siteRoot, pubRoot, linkRefStyle)}${fragment && '#' + fragment}[${text}]`
408
418
  }
409
419
  asciidoctorLogger.warn(
410
420
  doc.createLogMessage(
411
- `Cannot create external ${resourceId.family} reference in assembly because site URL is unknown: ${target}`,
421
+ `Cannot create external ${resourceId.family} reference in assembly because site URL is unknown: ${target_}`,
412
422
  { source_location: { file: relative, lineno: idx + 1 } }
413
423
  )
414
424
  )
415
425
  }
416
426
  const linkAttrlist = text
417
427
  ? (~text.indexOf(',') ? `"${text}"` : text) + ',role=unresolved'
418
- : 'role=unresolved'
419
- return `link:${target}[${linkAttrlist}]`
428
+ : (~target.indexOf(':') ? `${target},` : '') + 'role=unresolved'
429
+ return `link:${target_}[${linkAttrlist}]`
420
430
  }
421
431
  if (fragment === resource.asciidoc.id) fragment = ''
422
432
  if (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.16",
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)",