@antora/assembler 1.0.0-alpha.4 → 1.0.0-alpha.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.
@@ -27,13 +27,15 @@ function loadConfig (playbook, configSource = './antora-assembler.yml') {
27
27
  if (config.enabled === false) return undefined
28
28
  let asciidocAttrs
29
29
  if (!config.asciidoc) {
30
- config.asciidoc = { attributes: (asciidocAttrs = { doctype: 'book' }) }
30
+ config.asciidoc = { attributes: (asciidocAttrs = {}) }
31
31
  } else if (!(asciidocAttrs = config.asciidoc.attributes)) {
32
- config.asciidoc.attributes = asciidocAttrs = { doctype: 'book' }
32
+ config.asciidoc.attributes = asciidocAttrs = {}
33
33
  }
34
- Object.assign(asciidocAttrs, { revdate: new Date().toISOString().split('T')[0], 'page-partial': null })
34
+ if (!('doctype' in asciidocAttrs)) asciidocAttrs.doctype = 'book'
35
+ asciidocAttrs.revdate = new Date().toISOString().split('T')[0]
36
+ asciidocAttrs['page-partial'] = null
35
37
  if (config.componentVersions == null) {
36
- config.componentVersions = ['**']
38
+ config.componentVersions = ['*']
37
39
  } else if (typeof config.componentVersions === 'string') {
38
40
  config.componentVersions = config.componentVersions.split(', ')
39
41
  }
@@ -166,14 +166,18 @@ function aggregateAsciiDoc (
166
166
  buffer.push(`${'='.repeat(hlevel)} ${overviewTitle}`)
167
167
  if (toggleSectids) buffer.push(':sectids:')
168
168
  }
169
- const siteUrl = doc.getAttribute('site-url')
169
+ const siteUrl = ((val) => {
170
+ if (!val || val === '/') return ''
171
+ return val.charAt(val.length - 1) === '/' ? val.substr(0, val.length - 1) : val
172
+ })(doc.getAttribute('site-url'))
170
173
  const lines = doc.getSourceLines()
171
174
  const ignoreLines = []
172
175
  // TODO: think more about when multipart is allowed; perhaps configurable
173
176
  if (doc.hasSections()) fixSectionLevels(doc.getSections(), level === 0)
174
- const allBlocks = doc.findBy(
175
- { traverse_documents: true },
176
- (it) => it.getContext() !== 'document' && !(it.getContext() === 'table_cell' && it.getStyle() === 'asciidoc')
177
+ const allBlocks = doc.findBy({ traverse_documents: true }, (it) =>
178
+ it.getContext() === 'document'
179
+ ? it.getDocument().isNested()
180
+ : !(it.getContext() === 'table_cell' && it.getStyle() === 'asciidoc')
177
181
  )
178
182
  allBlocks.forEach((block) => {
179
183
  const contentModel = block.content_model
@@ -298,8 +302,8 @@ function aggregateAsciiDoc (
298
302
  // NOTE: lineno is not defined for preamble
299
303
  if (typeof lineno !== 'number') return
300
304
  const context = block.getContext()
301
- const idx = lineno - 1
302
- if (context === 'section') {
305
+ let idx = lineno - 1
306
+ if (context === 'section' && !block.getDocument().isNested()) {
303
307
  if (block.getSectionName() === 'header') {
304
308
  lines.splice(idx, 1)
305
309
  return
@@ -347,6 +351,9 @@ function aggregateAsciiDoc (
347
351
  }
348
352
  lastImageMacroAt = [idx, imageMacroOffset]
349
353
  }
354
+ } else if (context === 'document' && block.hasHeader()) {
355
+ // nested document
356
+ idx = (block.getHeader().getLineNumber() || idx + 1) - 1
350
357
  }
351
358
  if (block.getId()) rewriteStyleAttribute(block, lines, idx, idprefix)
352
359
  }
@@ -364,7 +371,7 @@ function aggregateAsciiDoc (
364
371
  } else if (val !== initialVal) {
365
372
  accum.push(`:${name}:${initialVal ? ' ' + initialVal : ''}`)
366
373
  }
367
- } else if (val != null && !doc.isAttributeLocked(name)) {
374
+ } else if (val != null && !(doc.isAttributeLocked(name) || name === 'doctype')) {
368
375
  accum.push(`:!${name}:`)
369
376
  }
370
377
  return accum
@@ -7,7 +7,9 @@ const selectMutableAttributes = require('./select-mutable-attributes')
7
7
  function produceAggregateDocuments (loadAsciiDoc, contentCatalog, assemblerConfig) {
8
8
  const { insertStartPage, rootLevel, sectionMergeStrategy, asciidoc: assemblerAsciiDocConfig } = assemblerConfig
9
9
  const assemblerAsciiDocAttributes = Object.assign({}, assemblerAsciiDocConfig.attributes)
10
- delete assemblerAsciiDocAttributes['source-highlighter'] // only used at convert time
10
+ const { doctype, 'source-highlighter': sourceHighlighter } = assemblerAsciiDocAttributes
11
+ delete assemblerAsciiDocAttributes.doctype
12
+ delete assemblerAsciiDocAttributes['source-highlighter']
11
13
  return filterComponentVersions(contentCatalog.getComponents(), assemblerConfig.componentVersions).reduce(
12
14
  (accum, componentVersion) => {
13
15
  const { name: componentName, version, title, navigation } = componentVersion
@@ -30,7 +32,8 @@ function produceAggregateDocuments (loadAsciiDoc, contentCatalog, assemblerConfi
30
32
  const mutableAttributes = startPage
31
33
  ? selectMutableAttributes(loadAsciiDoc, contentCatalog, startPage, mergedAsciiDocConfig)
32
34
  : {}
33
- return accum.concat(
35
+ delete mutableAttributes.doctype
36
+ accum = accum.concat(
34
37
  prepareOutlines(navigation, rootEntry, rootLevel).map((outline) =>
35
38
  produceAggregateDocument(
36
39
  loadAsciiDoc,
@@ -44,6 +47,11 @@ function produceAggregateDocuments (loadAsciiDoc, contentCatalog, assemblerConfi
44
47
  )
45
48
  )
46
49
  )
50
+ mergedAsciiDocConfig.attributes.doctype = doctype
51
+ sourceHighlighter
52
+ ? (mergedAsciiDocConfig.attributes['source-highlighter'] = sourceHighlighter)
53
+ : delete mergedAsciiDocConfig.attributes['source-highlighter']
54
+ return accum
47
55
  },
48
56
  []
49
57
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/assembler",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.5",
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)",
@@ -25,6 +25,7 @@
25
25
  "./filter-component-versions": "./lib/filter-component-versions.js",
26
26
  "./load-config": "./lib/load-config.js",
27
27
  "./produce-aggregate-document": "./lib/produce-aggregate-document.js",
28
+ "./produce-aggregate-documents": "./lib/produce-aggregate-documents.js",
28
29
  "./select-mutable-attributes": "./lib/select-mutable-attributes.js"
29
30
  },
30
31
  "dependencies": {