@antora/assembler 1.0.0-alpha.3 → 1.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.
@@ -105,7 +105,7 @@ function aggregateAsciiDoc (
105
105
  page = new page.constructor(Object.assign({}, page, { contents, mediaType: 'text/asciidoc' }))
106
106
  const { module: module_, relative, origin } = page.src
107
107
  const doc = loadAsciiDoc(page, contentCatalog, asciidocConfig)
108
- const ids = doc.getCatalog().ids
108
+ const refs = doc.getCatalog().refs
109
109
  // NOTE: in Antora, docname is relative src path from module without file extension
110
110
  const docname = doc.getAttribute('docname')
111
111
  //const idprefix = `${module_ === 'ROOT' ? '' : module_ + ':'}${docname}//`
@@ -206,11 +206,9 @@ function aggregateAsciiDoc (
206
206
  let line = lines[idx]
207
207
  if (~line.indexOf('<<')) {
208
208
  line = line.replace(/(?<![\\+])<<#?([\p{Alpha}0-9_/.:{][^>,]*?)(?:|, *([^>]+?))?>>/gu, (m, refid, text) => {
209
- // support natural xref; note this logic will change when upgrading to Asciidoctor 2
210
- if (!ids['$key?'](refid) && (~refid.indexOf(' ') || refid.toLowerCase() !== refid)) {
211
- if (!(refid = doc.getCatalog().ids.$key(refid).$to_s())) {
212
- return m
213
- }
209
+ // support natural xref
210
+ if (!refs['$key?'](refid) && (~refid.indexOf(' ') || refid.toLowerCase() !== refid)) {
211
+ if ((refid = doc.$resolve_id(refid))['$nil?']()) return m
214
212
  }
215
213
  return `<<${idprefix}${refid}${text ? ',' + text : ''}>>`
216
214
  })
@@ -221,21 +219,26 @@ function aggregateAsciiDoc (
221
219
  }
222
220
  if (~line.indexOf('xref:')) {
223
221
  // Q: should we allow : as first character of target?
224
- line = line.replace(/xref:([\p{Alpha}#/.{].*?)\[(|.*?[^\\])\]/gu, (m, target, text) => {
222
+ line = line.replace(/xref:([\p{Alpha}0-9_/.{#].*?)\[(|.*?[^\\])\]/gu, (m, target, text) => {
225
223
  let pagePart, fragment, targetPage
226
224
  const hashIdx = target.indexOf('#')
227
225
  if (~hashIdx) {
228
226
  pagePart = target.substr(0, hashIdx)
229
227
  fragment = target.substr(hashIdx + 1)
230
228
  // TODO: for now, assume .adoc; in the future, consider other file extensions
231
- if (!(pagePart && pagePart.endsWith('.adoc'))) pagePart += '.adoc'
229
+ if (pagePart && !pagePart.endsWith('.adoc')) pagePart += '.adoc'
232
230
  } else if (target.endsWith('.adoc')) {
233
231
  pagePart = target
234
232
  fragment = ''
235
233
  } else {
236
234
  fragment = target
237
235
  }
238
- if (!pagePart) return `<<${idprefix}${fragment}${text ? ',' + text.replace(/\\]/g, ']') : ''}>>`
236
+ if (!pagePart) {
237
+ // Q: should we validate the internal ID here?
238
+ return text && ~text.indexOf('=')
239
+ ? `xref:${idprefix}${fragment}[${text}]`
240
+ : `<<${idprefix}${fragment}${text ? ',' + text.replace(/\\]/g, ']') : ''}>>`
241
+ }
239
242
  if (~pagePart.indexOf('@') || /:.*:/.test(pagePart)) {
240
243
  // TODO: handle unresolved page better
241
244
  return siteUrl && (targetPage = contentCatalog.resolvePage(pagePart, page.src))
@@ -324,8 +327,7 @@ function aggregateAsciiDoc (
324
327
  ).lastIndexOf('image::')
325
328
  if (imageMacroOffset > 0) {
326
329
  if (
327
- block.getParent().getContext() === 'document' &&
328
- block.getParent().isNested() &&
330
+ block.getDocument().isNested() &&
329
331
  (prefix = line.substr(0, imageMacroOffset)).trimRight().endsWith('|')
330
332
  ) {
331
333
  line = line.substr(prefix.length)
@@ -6,9 +6,8 @@ const { PassThrough } = require('stream')
6
6
  class LazyReadable extends PassThrough {
7
7
  constructor (fn, options) {
8
8
  super(options)
9
- const _read = this._read
10
9
  this._read = function () {
11
- this._read = _read.bind(this)
10
+ delete this._read // restores original method
12
11
  fn.call(this, options).on('error', this.emit.bind(this, 'error')).pipe(this)
13
12
  return this._read.apply(this, arguments)
14
13
  }
@@ -43,11 +43,15 @@ async function runCommand (cmd, argv = [], opts = {}) {
43
43
  ps.on('error', (err) => reject(err.code === 'ENOENT' ? new Error(`Command not found: ${cmdv.join(' ')}`) : err))
44
44
  ps.stdout.on('data', (data) => (output ? process.stdout.write(data) : stdout.push(data)))
45
45
  ps.stderr.on('data', (data) => stderr.push(data))
46
- try {
47
- input instanceof Buffer ? ps.stdin.end(input) : ps.stdin.end()
48
- } catch (err) {
49
- reject(err)
50
- } finally {
46
+ if (input instanceof Buffer) {
47
+ try {
48
+ ps.stdin.on('error', () => undefined)
49
+ ps.stdin.end(input)
50
+ } catch (err) {
51
+ if (!ps.stdin.writableEnded) ps.stdin.end()
52
+ reject(err)
53
+ }
54
+ } else {
51
55
  ps.stdin.end()
52
56
  }
53
57
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "An extension library for Antora that assembles content from multiple pages into a single AsciiDoc file to converted and publish.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "OpenDevise Inc. (https://opendevise.com)",