UNPKG

@antora/assembler

Version:

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.

37 lines (31 loc) 1.22 kB
'use strict' const path = require('node:path/posix') function resolveEmbedTarget (resource, outDirname, referenceStyle, escapeForInline) { const target = referenceStyle === 'output-relative' ? resource.out.path : path.relative(outDirname + '/', resource.out.path) return escapeForInline ? target.replace(/_/g, '{underscore}') : target } function resolveLinkTarget (resource, siteRoot, pubRoot, referenceStyle, escapeForInline, ensurePrefix = true) { let target if (resource.site?.url) { target = ['', resource.pub.url] } else { switch (referenceStyle) { case 'absolute': target = ['', siteRoot.url + resource.pub.url] break case 'root-relative': target = [ensurePrefix ? 'link:' : '', siteRoot.path + resource.pub.url] break default: target = [ensurePrefix ? 'link:' : '', computeRelativeUrl(pubRoot + '/', resource.pub.url)] } } if (escapeForInline) target[1] = target[1].replace(/_/g, '{underscore}') return target.join('') } function computeRelativeUrl (from, to) { const rel = path.relative(from, to) return to.charAt(to.length - 1) === '/' ? rel + '/' : rel } module.exports = { resolveEmbedTarget, resolveLinkTarget }