@antora/assembler 1.0.0-rc.1 → 1.0.0-rc.2

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.
@@ -148,7 +148,7 @@ function generateSelectAssemblyProfile (context, contentCatalog, baseModel, intr
148
148
  const navigation = navigationCatalog?.getNavigation(componentVersion.name, componentVersion.version)
149
149
  const attributes = Object.assign({}, baseModel.attributes)
150
150
  const model = Object.assign({}, baseModel, overrides, { attributes, logger })
151
- if (!overrides) return navigation ? Object.assign(model, { navigation }) : model
151
+ if (!overrides) return Object.assign(model, { navigation: navigation || componentVersion.navigation })
152
152
  delete model.navFiles
153
153
  delete model.messages
154
154
  if (overrides.attributes) Object.entries(overrides.attributes).forEach(([name, val]) => (attributes[name] = val))
@@ -98,14 +98,19 @@ function loadConfig (playbook, configSource, preferredQualifier = '') {
98
98
  build.dir &&= expandPath(build.dir, { dot: playbook.dir })
99
99
  // used as cwd of command (and any scripts it requires)
100
100
  build.cwd = build.cwd == null ? playbook.dir : expandPath(build.cwd, { dot: playbook.dir })
101
- if (build.command?.includes('$')) {
102
- const vars = {
103
- $NODE: process.execPath,
104
- $NPM: ospath.join(process.execPath, '../npm'),
105
- $NPX: ospath.join(process.execPath, '../npx'),
106
- $PWD: build.cwd,
101
+ const command = build.command
102
+ if (command) {
103
+ if (command.constructor !== String) {
104
+ build.command = String(command)
105
+ } else if (command.includes('$')) {
106
+ const vars = {
107
+ $NODE: process.execPath,
108
+ $NPM: ospath.join(process.execPath, '../npm'),
109
+ $NPX: ospath.join(process.execPath, '../npx'),
110
+ $PWD: build.cwd,
111
+ }
112
+ build.command = build.command.replace(/^\$(?:NODE|NP[MX])(?= )|\$PWD\b/g, (ref) => vars[ref])
107
113
  }
108
- build.command = build.command.replace(/^\$(?:NODE|NP[MX])(?= )|\$PWD\b/g, (ref) => vars[ref])
109
114
  }
110
115
  if (!('clean' in build) && 'output' in playbook) build.clean = playbook.output.clean
111
116
  if (!('publish' in build)) build.publish = true
@@ -181,7 +181,7 @@ function mergeAsciiDoc (
181
181
  let navtitlePlain = sanitize(navtitle)
182
182
  let navtitleAsciiDoc = unconvertInlineAsciiDoc(navtitle)
183
183
  const { items = [], roles = [], unresolved, urlType, url } = outlineEntry
184
- const { filetype, linkReferenceStyle, pubRoot, siteRoot, logger, rootLevel } = assemblyModel
184
+ const { filetype, linkReferenceStyle, pubRoot, sectionMergeStrategy, siteRoot, logger, rootLevel } = assemblyModel
185
185
  const assembled = pagesInOutline.assembled
186
186
  // FIXME: ideally, resource ID would be stored in navigation so we can look up the page more efficiently
187
187
  const page = urlType === 'internal' && !unresolved ? pagesInOutline.get(url) : undefined
@@ -231,13 +231,7 @@ function mergeAsciiDoc (
231
231
  let pageFragment = ''
232
232
  let pageRoles = []
233
233
  let pageStyle = doc.getAttribute('assembly-style', '')
234
- if (
235
- !pageStyle &&
236
- atBookRoot &&
237
- rootLevel === 0 &&
238
- assemblyModel.sectionMergeStrategy === 'fuse' &&
239
- !doc.source_header_attributes['$key?']('assembly-style')
240
- ) {
234
+ if (!pageStyle && atBookRoot && rootLevel === 0 && !doc.source_header_attributes['$key?']('assembly-style')) {
241
235
  pageStyle = 'preface'
242
236
  }
243
237
  let part
@@ -248,6 +242,7 @@ function mergeAsciiDoc (
248
242
  pageStyle = pageStyle.substring(0, pageStyle.length - 5)
249
243
  if (!supportsParts) part = undefined
250
244
  }
245
+ const hasSections = doc.hasSections()
251
246
  let nextSectionLevel = 1
252
247
  const lines = doc.getSourceLines()
253
248
  const ignoreLines = []
@@ -353,15 +348,16 @@ function mergeAsciiDoc (
353
348
  ? ''
354
349
  : undefined
355
350
  if (htitleOverride != null) {
351
+ const keepSections = hasSections && sectionMergeStrategy !== 'discrete'
356
352
  if (htitleOverride === '') {
357
- if (headerHasBlockAttrs || doc.hasSections()) {
353
+ if (headerHasBlockAttrs || keepSections) {
358
354
  htitleAsciiDoc = '{empty}'
359
355
  notitle = true
360
356
  } else {
361
357
  if (hasPrefaceTitleAttr) buffer.splice(++buffer.endHeaderIdx, 0, ':preface-title:')
362
358
  htitleAsciiDoc = undefined
363
359
  }
364
- } else if (hasPrefaceTitleAttr && !(headerHasBlockAttrs || doc.hasSections())) {
360
+ } else if (hasPrefaceTitleAttr && !headerHasBlockAttrs && !keepSections) {
365
361
  buffer.splice(++buffer.endHeaderIdx, 0, `:preface-title: ${unconvertInlineAsciiDoc(htitleOverride)}`)
366
362
  htitleAsciiDoc = undefined
367
363
  } else {
@@ -405,7 +401,7 @@ function mergeAsciiDoc (
405
401
  buffer.push(`${'='.repeat(heading.level)} ${heading.title}`)
406
402
  } else {
407
403
  if (atDocumentRoot) buffer.unshift(`[#${pageId}]`)
408
- if (assemblyModel.sectionMergeStrategy === 'enclose' && hasItems && doc.hasSections()) {
404
+ if (sectionMergeStrategy === 'enclose' && hasItems && hasSections) {
409
405
  enclosed = true
410
406
  // TODO: make overview section title configurable
411
407
  //let overviewTitle = doc.getDocumentTitle()
@@ -424,14 +420,14 @@ function mergeAsciiDoc (
424
420
  }
425
421
  }
426
422
  assembled.pages.set(page, pageFragment)
427
- if (doc.hasSections()) fixSectionLevels(doc.getSections(), nextSectionLevel)
423
+ if (hasSections) fixSectionLevels(doc.getSections(), nextSectionLevel)
428
424
  const allBlocks = doc.findBy({ traverse_documents: true }, (it) =>
429
425
  it.getContext() === 'document'
430
426
  ? it.getDocument().isNested()
431
427
  : !(it.getContext() === 'table_cell' && it.getStyle() === 'asciidoc')
432
428
  )
433
429
  if (doc.getDoctype() === 'manpage') {
434
- const firstSectionIdx = doc.hasSections() ? doc.getSections()[0].getLineNumber() - 1 : lines.length
430
+ const firstSectionIdx = hasSections ? doc.getSections()[0].getLineNumber() - 1 : lines.length
435
431
  for (let idx = 0; idx < firstSectionIdx; idx++) {
436
432
  if (~ignoreLines.indexOf(idx)) continue
437
433
  const line = lines[idx]
@@ -547,7 +543,7 @@ function mergeAsciiDoc (
547
543
  let idx = lineno - 1
548
544
  if (context === 'section' && !block.getDocument().isNested()) {
549
545
  if (block.getSectionName() === 'header') return
550
- let blockStyle = (assemblyModel.sectionMergeStrategy || 'discrete') === 'discrete' ? 'discrete' : undefined
546
+ let blockStyle = sectionMergeStrategy === 'discrete' ? 'discrete' : undefined
551
547
  lines[idx] = lines[idx].replace(/^=+ (.+)/, (_, rest) => {
552
548
  let targetMarkerLength = block.level + 1 + level + (enclosed ? 1 : 0)
553
549
  if (targetMarkerLength > 6) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.0.0-rc.2",
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)",
@@ -41,7 +41,7 @@
41
41
  "@asciidoctor/reducer": "~1.1",
42
42
  "@antora/expand-path-helper": "~3.0",
43
43
  "@antora/run-command-helper": "~1.1",
44
- "js-yaml": "~4.2"
44
+ "js-yaml": "~4.3"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@antora/asciidoc-loader": "3.2.0-rc.2",