@antora/assembler 1.0.0-alpha.2 → 1.0.0-alpha.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.
@@ -171,22 +171,10 @@ function aggregateAsciiDoc (
171
171
  const ignoreLines = []
172
172
  // TODO: think more about when multipart is allowed; perhaps configurable
173
173
  if (doc.hasSections()) fixSectionLevels(doc.getSections(), level === 0)
174
- // TODO: update / simplify findBy calls when upgrading to Asciidoctor 2
175
- const allBlocks = doc
176
- .findBy((it) => it.getContext() !== 'document')
177
- .reduce((accum, block) => {
178
- accum.push(block)
179
- if (block.getContext() === 'table') {
180
- const rows = block.rows
181
- ;[...rows.body, ...rows.foot].forEach((row) => {
182
- row.forEach((cell) => {
183
- if (cell.style !== 'asciidoc') return
184
- accum.push(...cell.inner_document.findBy((it) => it.getContext() !== 'document'))
185
- })
186
- })
187
- }
188
- return accum
189
- }, [])
174
+ const allBlocks = doc.findBy(
175
+ { traverse_documents: true },
176
+ (it) => it.getContext() !== 'document' && !(it.getContext() === 'table_cell' && it.getStyle() === 'asciidoc')
177
+ )
190
178
  allBlocks.forEach((block) => {
191
179
  const contentModel = block.content_model
192
180
  if (
@@ -301,6 +289,7 @@ function aggregateAsciiDoc (
301
289
  // NOTE: need to do this last since it modifies the line numbers
302
290
  // we could remap the line numbers to make them resilient
303
291
  // or we could mark which lines to remove and filter them after
292
+ let lastImageMacroAt
304
293
  ;[...allBlocks].reverse().forEach((block) => {
305
294
  const lineno = block.getLineNumber()
306
295
  // NOTE: lineno is not defined for preamble
@@ -327,33 +316,34 @@ function aggregateAsciiDoc (
327
316
  if (block.getId()) rewriteStyleAttribute(block, lines, idx, idprefix, blockStyle)
328
317
  } else {
329
318
  if (context === 'image') {
330
- const atImageMacro = (lines[idx] || '').startsWith('image::')
331
- // NOTE: the following logic is needed only if parser is messing up line number of image block
332
- //let atImageMacro
333
- //// NOTE: account for line number tracking error in parser when image has block anchor
334
- //if (block.getId()) {
335
- // const originalIdx = idx
336
- // let line
337
- // while ((line = lines[idx]) != null && !(atImageMacro = line.startsWith('image::'))) idx++
338
- // if (!atImageMacro) {
339
- // idx = originalIdx
340
- // if ((lines[idx - 1] || '').startsWith('image::')) {
341
- // atImageMacro = true
342
- // idx--
343
- // }
344
- // }
345
- //} else if ((lines[idx] || '').startsWith('image::')) {
346
- // atImageMacro = true
347
- //}
348
- const target = block.getAttribute('target')
349
- if (atImageMacro && isResourceSpec(target)) {
350
- const image = contentCatalog.resolveResource(target, page.src, 'image', ['image'])
351
- // FIXME: handle (or report) case when image is not resolved
352
- if (image) {
353
- image.out.assembled = true
354
- const line = lines[idx]
355
- lines[idx] = `image::${image.pub.url.substr(1)}${line.substr(line.indexOf('['))}`
319
+ let line = lines[idx] || ''
320
+ let prefix = ''
321
+ // Q: can we use startsWith('image::') in certain cases?
322
+ let imageMacroOffset = (
323
+ lastImageMacroAt && lastImageMacroAt[0] === idx ? line.substr(0, lastImageMacroAt[1]) : line
324
+ ).lastIndexOf('image::')
325
+ if (imageMacroOffset > 0) {
326
+ if (
327
+ block.getParent().getContext() === 'document' &&
328
+ block.getParent().isNested() &&
329
+ (prefix = line.substr(0, imageMacroOffset)).trimRight().endsWith('|')
330
+ ) {
331
+ line = line.substr(prefix.length)
332
+ } else {
333
+ imageMacroOffset = -1
334
+ }
335
+ }
336
+ if (imageMacroOffset >= 0) {
337
+ const target = block.getAttribute('target')
338
+ if (isResourceSpec(target)) {
339
+ const image = contentCatalog.resolveResource(target, page.src, 'image', ['image'])
340
+ // FIXME: handle (or report) case when image is not resolved
341
+ if (image) {
342
+ lines[idx] = `${prefix}image::${image.pub.url.substr(1)}${line.substr(line.indexOf('['))}`
343
+ image.out.assembled = true
344
+ }
356
345
  }
346
+ lastImageMacroAt = [idx, imageMacroOffset]
357
347
  }
358
348
  }
359
349
  if (block.getId()) rewriteStyleAttribute(block, lines, idx, idprefix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
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)",