@antora/assembler 1.0.0-rc.8 → 1.0.0-rc.9
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.
|
@@ -16,12 +16,13 @@ async function compileConversionAttributes (doc, targetExtname, assemblerConfig,
|
|
|
16
16
|
const outdir = ospath.dirname(docfile)
|
|
17
17
|
const outfile = docfile.substring(0, docfile.length - docfilesuffix.length) + targetExtname
|
|
18
18
|
const docdir = relativeToOutput ? dir : outdir
|
|
19
|
-
const imagesoutdir = ospath.join(outdir, '..', '_images')
|
|
19
|
+
//const imagesoutdir = ospath.join(outdir, '..', '_images/generated')
|
|
20
|
+
const imagesoutdir = outdir
|
|
20
21
|
const attributes = Object.assign({ revdate: `${assemblerConfig.assembly.revdate}@` }, docAttributes, {
|
|
21
22
|
docdir,
|
|
22
23
|
docfile,
|
|
23
24
|
docfilesuffix,
|
|
24
|
-
docname
|
|
25
|
+
docname,
|
|
25
26
|
imagesdir: '',
|
|
26
27
|
imagesoutdir,
|
|
27
28
|
outdir,
|
package/lib/constants.js
CHANGED
|
@@ -52,7 +52,7 @@ function produceAssemblyFile (
|
|
|
52
52
|
src: { component, version, module: 'ROOT', family: 'page', relative: '_.adoc', path: '_.adoc' },
|
|
53
53
|
},
|
|
54
54
|
undefined,
|
|
55
|
-
asciidocConfig
|
|
55
|
+
Object.assign({}, asciidocConfig, { antoraResourceRefs: false, extensions: [] })
|
|
56
56
|
)
|
|
57
57
|
const idSeparators = {
|
|
58
58
|
prefix:
|
|
@@ -223,7 +223,8 @@ function mergeAsciiDoc (
|
|
|
223
223
|
let navtitle = outlineEntry.navtitle ?? (page && hash ? page.asciidoc.navtitle : outlineEntry.content)
|
|
224
224
|
let navtitlePlain = sanitize(navtitle)
|
|
225
225
|
let navtitleAsciiDoc = unconvertInlineAsciiDoc(navtitle)
|
|
226
|
-
const { filetype, linkReferenceStyle, pubRoot,
|
|
226
|
+
const { filetype, linkReferenceStyle, pubRoot, siteRoot, logger, rootLevel, rootPageStyle } = assemblyModel
|
|
227
|
+
let sectionMergeStrategy = assemblyModel.sectionMergeStrategy
|
|
227
228
|
const doctype = assemblyModel.doctype
|
|
228
229
|
const atDocumentRoot = !builder.body?.length
|
|
229
230
|
let atBookRoot = atDocumentRoot && !level && doctype === 'book' && (supportsParts = true)
|
|
@@ -238,16 +239,9 @@ function mergeAsciiDoc (
|
|
|
238
239
|
Object.assign({}, page, { contents: Buffer.from(contents.toString().trimEnd()), mediaType: page.src.mediaType })
|
|
239
240
|
)
|
|
240
241
|
const doc = loadAsciiDoc(pageAsAsciiDoc, contentCatalog, asciidocConfig)
|
|
242
|
+
if (typeof doc.applyLogger === 'function') doc.applyLogger()
|
|
243
|
+
if (logger) doc.getLogger().delegate = logger
|
|
241
244
|
doc.catalog.syntheticIds = {}
|
|
242
|
-
doc.logger = logger
|
|
243
|
-
? Object.assign(doc.getLogger().$dup(), {
|
|
244
|
-
delegate: {
|
|
245
|
-
warn () {
|
|
246
|
-
return logger.warn.apply(logger, arguments)
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
})
|
|
250
|
-
: doc.getLogger()
|
|
251
245
|
doc.source_header_attributes ??= toHash()
|
|
252
246
|
const isRootPage = atDocumentRoot && !level
|
|
253
247
|
const { component, version, module: module_, relative, origin } = page.src
|
|
@@ -270,6 +264,7 @@ function mergeAsciiDoc (
|
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
266
|
}
|
|
267
|
+
const overviewTitle = doc.getAttribute('overview-title', 'Overview')
|
|
273
268
|
// NOTE: in Antora, docname is relative src path from module without file extension
|
|
274
269
|
const docname = doc.getAttribute('docname')
|
|
275
270
|
const pageId = generateScopedId(page.src, componentVersion, idSeparators, filetype)
|
|
@@ -277,8 +272,8 @@ function mergeAsciiDoc (
|
|
|
277
272
|
let pageFragment = `#${pageId}`
|
|
278
273
|
let pageRoles = []
|
|
279
274
|
let pageStyle = doc.getAttribute('assembly-style', '')
|
|
280
|
-
if (!pageStyle &&
|
|
281
|
-
pageStyle = '
|
|
275
|
+
if (!pageStyle && isRootPage && !doc.source_header_attributes['$key?']('assembly-style')) {
|
|
276
|
+
pageStyle = rootPageStyle || ''
|
|
282
277
|
}
|
|
283
278
|
let part
|
|
284
279
|
if ((part = pageStyle === 'part')) {
|
|
@@ -289,40 +284,22 @@ function mergeAsciiDoc (
|
|
|
289
284
|
if (!supportsParts) part = undefined
|
|
290
285
|
}
|
|
291
286
|
const hasSections = doc.hasSections()
|
|
287
|
+
const encloseSections = sectionMergeStrategy === 'enclose' && hasItems && hasSections
|
|
292
288
|
let nextSectionLevel = 1
|
|
293
289
|
const lines = doc.getSourceLines()
|
|
294
290
|
const ignoreLines = []
|
|
295
291
|
const buffer = (builder.body ??= [])
|
|
296
292
|
if (buffer.length) buffer.push('')
|
|
297
|
-
buffer.push(`:docname: ${docname}`)
|
|
298
|
-
if (component !== builder.currentComponentVersion.name) {
|
|
299
|
-
const thisComponentVersion =
|
|
300
|
-
component === componentVersion.name && version === componentVersion.version
|
|
301
|
-
? componentVersion
|
|
302
|
-
: contentCatalog.getComponentVersion(component, version)
|
|
303
|
-
if (thisComponentVersion) {
|
|
304
|
-
buffer.push(`:page-component-name: ${thisComponentVersion.name}`)
|
|
305
|
-
buffer.push(`:page-component-version:${thisComponentVersion.version ? ' ' + thisComponentVersion.version : ''}`)
|
|
306
|
-
buffer.push(':page-version: {page-component-version}')
|
|
307
|
-
buffer.push(`:page-component-display-version: ${thisComponentVersion.displayVersion}`)
|
|
308
|
-
buffer.push(`:page-component-title: ${thisComponentVersion.title}`)
|
|
309
|
-
builder.currentComponentVersion = thisComponentVersion
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
buffer.push(`:page-module: ${module_}`)
|
|
313
|
-
buffer.push(`:page-relative-src-path: ${relative}`)
|
|
314
|
-
buffer.push(`:page-origin-url: ${origin.url}`)
|
|
315
|
-
buffer.push(`:page-origin-start-path:${origin.startPath && ' '}${origin.startPath}`)
|
|
316
|
-
buffer.push(`:page-origin-refname: ${origin.branch || origin.tag}`)
|
|
317
|
-
buffer.push(`:page-origin-reftype: ${origin.branch ? 'branch' : 'tag'}`)
|
|
318
|
-
buffer.push(`:page-origin-refhash: ${origin.worktree ? '(worktree)' : origin.refhash}`)
|
|
319
293
|
if (doc.hasHeader()) {
|
|
320
294
|
for (const entry of processDocumentHeader(doc, lines, ignoreLines, isRootPage)) {
|
|
321
295
|
if (entry.type === 'author_line') {
|
|
322
296
|
builder.setAuthor(entry.lines[0])
|
|
323
297
|
} else if (entry.type === 'attribute_entry') {
|
|
324
298
|
const name = entry.name
|
|
325
|
-
if (
|
|
299
|
+
if (entry.negated && name === 'sectnums') {
|
|
300
|
+
// catch sectnums missed by reducer; only allow turned off, not turning on
|
|
301
|
+
doc.source_header_attributes['$[]=']('sectnums', null)
|
|
302
|
+
} else if (!entry.negated && !doc.isAttributeLocked(name)) {
|
|
326
303
|
let val, newVal
|
|
327
304
|
if (
|
|
328
305
|
name.endsWith('-image') &&
|
|
@@ -369,46 +346,81 @@ function mergeAsciiDoc (
|
|
|
369
346
|
pageRoles = doc.getRoles()
|
|
370
347
|
}
|
|
371
348
|
if (roles.length) pageRoles = pageRoles.concat(roles[0] === 'page' ? roles.slice(1) : roles)
|
|
349
|
+
buffer.push(`:page-docname: ${docname}`)
|
|
350
|
+
if (component !== builder.currentComponentVersion.name) {
|
|
351
|
+
const thisComponentVersion =
|
|
352
|
+
component === componentVersion.name && version === componentVersion.version
|
|
353
|
+
? componentVersion
|
|
354
|
+
: contentCatalog.getComponentVersion(component, version)
|
|
355
|
+
if (thisComponentVersion) {
|
|
356
|
+
buffer.push(`:page-component-name: ${thisComponentVersion.name}`)
|
|
357
|
+
buffer.push(`:page-component-version:${thisComponentVersion.version ? ' ' + thisComponentVersion.version : ''}`)
|
|
358
|
+
buffer.push(':page-version: {page-component-version}')
|
|
359
|
+
buffer.push(`:page-component-display-version: ${thisComponentVersion.displayVersion}`)
|
|
360
|
+
buffer.push(`:page-component-title: ${thisComponentVersion.title}`)
|
|
361
|
+
builder.currentComponentVersion = thisComponentVersion
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
buffer.push(`:page-module: ${module_}`)
|
|
365
|
+
buffer.push(`:page-relative-src-path: ${relative}`)
|
|
366
|
+
buffer.push(`:page-origin-url: ${origin.url}`)
|
|
367
|
+
buffer.push(`:page-origin-start-path:${origin.startPath && ' '}${origin.startPath}`)
|
|
368
|
+
buffer.push(`:page-origin-refname: ${origin.branch || origin.tag}`)
|
|
369
|
+
buffer.push(`:page-origin-reftype: ${origin.branch ? 'branch' : 'tag'}`)
|
|
370
|
+
buffer.push(`:page-origin-refhash: ${origin.worktree ? '(worktree)' : origin.refhash}`)
|
|
372
371
|
let heading
|
|
373
372
|
if (pageStyle && (part && level === 1 ? (level = 0) : level) === 0) {
|
|
374
373
|
let htitleAsciiDoc = navtitleAsciiDoc
|
|
375
|
-
let notitle
|
|
376
374
|
if (pageStyle === 'preface') {
|
|
377
375
|
const hasPrefaceTitleAttr =
|
|
378
376
|
doc.isAttribute('preface-title') ||
|
|
379
377
|
doc.source_header_attributes['$key?']('preface-title') ||
|
|
380
378
|
doc.isAttributeLocked('preface-title')
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
379
|
+
let htitleOverride
|
|
380
|
+
if (hasPrefaceTitleAttr) {
|
|
381
|
+
htitleOverride = doc.getAttribute('preface-title', '')
|
|
382
|
+
} else if (encloseSections && !hasAssemblyNavtitleAttr) {
|
|
383
|
+
htitleOverride = overviewTitle
|
|
384
|
+
} else if (atDocumentRoot && (rootLevel ? true : !hasAssemblyNavtitleAttr)) {
|
|
385
|
+
htitleOverride = ''
|
|
386
|
+
}
|
|
387
|
+
const usePrefaceTitleAttr = hasPrefaceTitleAttr && atBookRoot
|
|
386
388
|
if (htitleOverride != null) {
|
|
387
|
-
const
|
|
389
|
+
const hasSectionsInAssembly = hasSections && sectionMergeStrategy !== 'discrete'
|
|
388
390
|
if (htitleOverride === '') {
|
|
389
|
-
|
|
391
|
+
nextSectionLevel = 2
|
|
392
|
+
sectionMergeStrategy = 'discrete'
|
|
393
|
+
if (builder.headerHasBlockAttrs) {
|
|
390
394
|
htitleAsciiDoc = '{empty}'
|
|
391
|
-
notitle = true
|
|
392
395
|
} else {
|
|
393
|
-
if (
|
|
396
|
+
if (usePrefaceTitleAttr) builder.header.push(':preface-title:')
|
|
394
397
|
htitleAsciiDoc = undefined
|
|
395
398
|
}
|
|
396
|
-
} else if (
|
|
399
|
+
} else if (usePrefaceTitleAttr && !(builder.headerHasBlockAttrs || hasSectionsInAssembly)) {
|
|
397
400
|
builder.header.push(`:preface-title: ${unconvertInlineAsciiDoc(htitleOverride)}`)
|
|
398
401
|
htitleAsciiDoc = undefined
|
|
399
402
|
} else {
|
|
400
403
|
htitleAsciiDoc = unconvertInlineAsciiDoc(htitleOverride)
|
|
401
404
|
}
|
|
402
405
|
}
|
|
406
|
+
} else if (encloseSections && atDocumentRoot && !hasAssemblyNavtitleAttr) {
|
|
407
|
+
htitleAsciiDoc = unconvertInlineAsciiDoc(overviewTitle)
|
|
403
408
|
}
|
|
404
409
|
if (htitleAsciiDoc) {
|
|
405
410
|
if (atDocumentRoot) {
|
|
406
411
|
// Q: should we use htitleAsciiDoc to generate ID if not {empty} instead of pageStyle
|
|
407
412
|
pageFragment = `#_${idSeparators.coordinate}${pageIdLeader}${pageStyle}`
|
|
408
413
|
builder.setDocid(pageId)
|
|
414
|
+
if (pageStyle === 'preface' && !atBookRoot) {
|
|
415
|
+
if (doc.hasAttribute('sectnums')) {
|
|
416
|
+
doc.source_header_attributes['$[]=']('sectnums', null)
|
|
417
|
+
buffer.push(':!sectnums:')
|
|
418
|
+
}
|
|
419
|
+
pageStyle = ''
|
|
420
|
+
}
|
|
409
421
|
}
|
|
410
422
|
heading = { title: htitleAsciiDoc, level: part ? 1 : 2 }
|
|
411
|
-
if (
|
|
423
|
+
if (htitleAsciiDoc === '{empty}') heading.notitle = true
|
|
412
424
|
nextSectionLevel = 2 // next section level is 2, even for special part
|
|
413
425
|
}
|
|
414
426
|
} else if (level) {
|
|
@@ -435,11 +447,7 @@ function mergeAsciiDoc (
|
|
|
435
447
|
}
|
|
436
448
|
if (isRootPage || (atDocumentRoot && !heading)) assembled.pages.rootPageFragment = pageFragment
|
|
437
449
|
assembled.pages.set(page, pageFragment)
|
|
438
|
-
if (
|
|
439
|
-
// TODO: make overview section title configurable
|
|
440
|
-
//let overviewTitle = doc.getDocumentTitle()
|
|
441
|
-
//if (overviewTitle === navtitle) overviewTitle = doc.getAttribute('overview-title', 'Overview')
|
|
442
|
-
const overviewTitle = doc.getAttribute('overview-title', 'Overview')
|
|
450
|
+
if (encloseSections && !(atDocumentRoot && heading)) {
|
|
443
451
|
const syntheticId = idSeparators.generateIdFromTitle(overviewTitle, idSeparators, pageIdLeader)
|
|
444
452
|
if (heading && buffer.length) buffer.push('')
|
|
445
453
|
let hlevel = level + (nextSectionLevel = 2)
|
|
@@ -645,6 +653,7 @@ function mergeAsciiDoc (
|
|
|
645
653
|
)
|
|
646
654
|
if (resolvedAttributeEntries.length > 1) safePush(buffer, resolvedAttributeEntries)
|
|
647
655
|
}
|
|
656
|
+
if (typeof doc.restoreLogger === 'function') doc.restoreLogger()
|
|
648
657
|
} else if (level && !hash) {
|
|
649
658
|
const buffer = (builder.body ??= [])
|
|
650
659
|
if (atDocumentRoot && rootLevel === 0 && navtitlePlain === componentVersion.title) {
|
|
@@ -721,8 +730,7 @@ function processDocumentHeader (doc, lines, ignoreLines, isRootPage) {
|
|
|
721
730
|
}
|
|
722
731
|
assemblyHeaderAttributes.delete('%authors')
|
|
723
732
|
}
|
|
724
|
-
const
|
|
725
|
-
for (const name of assemblyHeaderAttributes) headerAttributes.$delete(name)
|
|
733
|
+
for (const name of assemblyHeaderAttributes) doc.source_header_attributes.$delete(name)
|
|
726
734
|
}
|
|
727
735
|
const doctitleIdx = doc.getHeader().getLineNumber() - 1
|
|
728
736
|
const end = doc.getBlocks()[0]?.getLineNumber() ?? lines.length
|
|
@@ -18,6 +18,7 @@ function produceAssemblyFiles (
|
|
|
18
18
|
doctype: assemblyConfig.doctype,
|
|
19
19
|
insertStartPage: assemblyConfig.insertStartPage,
|
|
20
20
|
rootLevel: assemblyConfig.rootLevel,
|
|
21
|
+
rootPageStyle: assemblyConfig.rootPageStyle,
|
|
21
22
|
sectionMergeStrategy: assemblyConfig.sectionMergeStrategy,
|
|
22
23
|
navigation: componentVersion.navigation,
|
|
23
24
|
xmlIds: assemblyConfig.xmlIds,
|
|
@@ -130,7 +131,7 @@ function includedInNav (items, url) {
|
|
|
130
131
|
|
|
131
132
|
function resolveStartPage (contentCatalog, componentVersion, insertStartPage, outlineRoot) {
|
|
132
133
|
const { name: componentName, version } = componentVersion
|
|
133
|
-
|
|
134
|
+
const startPage =
|
|
134
135
|
'startPage' in componentVersion
|
|
135
136
|
? componentVersion.startPage
|
|
136
137
|
: contentCatalog.resolvePage('index.adoc', { component: componentName, version })
|
|
@@ -139,22 +140,19 @@ function resolveStartPage (contentCatalog, componentVersion, insertStartPage, ou
|
|
|
139
140
|
const navtitle = startPage.asciidoc?.navtitle || outlineRoot.content
|
|
140
141
|
Object.assign(outlineRoot, { navtitle, url: startPage.pub.url, urlType: 'internal', roles: ['page'] })
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
-
startPage = contentCatalog.createFile({
|
|
144
|
-
src: {
|
|
145
|
-
component: componentName,
|
|
146
|
-
version,
|
|
147
|
-
componentVersion,
|
|
148
|
-
module: 'ROOT',
|
|
149
|
-
family: 'page',
|
|
150
|
-
relative: 'index.adoc',
|
|
151
|
-
origin: componentVersion.origins?.values().next().value,
|
|
152
|
-
},
|
|
153
|
-
})
|
|
154
|
-
// FIXME remove once upgrading to Antora 3.2.0
|
|
155
|
-
startPage.path = ['modules', startPage.src.module, startPage.src.family + 's', startPage.src.relative].join('/')
|
|
143
|
+
return startPage
|
|
156
144
|
}
|
|
157
|
-
return
|
|
145
|
+
return contentCatalog.createFile({
|
|
146
|
+
src: {
|
|
147
|
+
component: componentName,
|
|
148
|
+
version,
|
|
149
|
+
componentVersion,
|
|
150
|
+
module: 'ROOT',
|
|
151
|
+
family: 'page',
|
|
152
|
+
relative: 'index.adoc',
|
|
153
|
+
origin: componentVersion.origins?.values().next().value,
|
|
154
|
+
},
|
|
155
|
+
})
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
function prepareOutlines (navigation, rootEntry, rootLevel) {
|
|
@@ -13,7 +13,7 @@ function identifyMutableAttributes (loadAsciiDoc, contentCatalog, referencePage,
|
|
|
13
13
|
Object.assign({}, referencePage, { contents: Buffer.alloc(0), mediaType: 'text/asciidoc' })
|
|
14
14
|
),
|
|
15
15
|
contentCatalog,
|
|
16
|
-
asciidocConfig
|
|
16
|
+
Object.assign({}, asciidocConfig, { extensions: [], headerOnly: true })
|
|
17
17
|
)
|
|
18
18
|
const immutableAttributeNames = doc.attribute_overrides.$keys()['$+'](['doctype'])
|
|
19
19
|
return Object.entries(doc.getAttributes()).reduce((accum, [name, val]) => {
|
package/lib/util/rewriter.js
CHANGED
|
@@ -86,7 +86,7 @@ function rewriteXref (
|
|
|
86
86
|
}
|
|
87
87
|
if (sourceLocation) {
|
|
88
88
|
const msg = `Cannot create external ${family} reference in assembly because site URL is unknown: ${rawTarget}`
|
|
89
|
-
doc.
|
|
89
|
+
doc.getLogger().warn(doc.createLogMessage(msg, { source_location: sourceLocation }))
|
|
90
90
|
}
|
|
91
91
|
} else if (~target.indexOf(':')) {
|
|
92
92
|
defaultText = rawTarget // use explicit text so AsciiDoc processor displays it correctly
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antora/assembler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
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)",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"js-yaml": "~5.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@antora/asciidoc-loader": "3.2.0-rc.
|
|
46
|
-
"@antora/navigation-builder": "3.2.0-rc.
|
|
47
|
-
"@antora/site-publisher": "3.2.0-rc.
|
|
45
|
+
"@antora/asciidoc-loader": "3.2.0-rc.3",
|
|
46
|
+
"@antora/navigation-builder": "3.2.0-rc.3",
|
|
47
|
+
"@antora/site-publisher": "3.2.0-rc.3"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": ">=20.0.0"
|