@antora/asciidoc-loader
Advanced tools
Comparing version 1.0.3 to 1.1.0
'use strict' | ||
module.exports = Object.freeze({ | ||
EXAMPLES_DIR_PROXY: 'example$', | ||
PARTIALS_DIR_PROXY: 'partial$', | ||
EXAMPLES_DIR_TOKEN: 'example$', | ||
PARTIALS_DIR_TOKEN: 'partial$', | ||
}) |
@@ -29,2 +29,5 @@ 'use strict' | ||
reader.pushInclude(includeContents, resolvedFile.file, resolvedFile.path, startLineNum, attrs) | ||
if (resolvedFile.context) { | ||
;(reader.file = new String(reader.file)).context = resolvedFile.context // eslint-disable-line no-new-wrappers | ||
} | ||
// TODO after upgrading to 1.5.7, pass partial-option attribute instead | ||
@@ -31,0 +34,0 @@ doc.getCatalog().includes.$replace(includes) |
@@ -6,3 +6,3 @@ 'use strict' | ||
const { EXAMPLES_DIR_PROXY, PARTIALS_DIR_PROXY } = require('../constants') | ||
const { EXAMPLES_DIR_TOKEN, PARTIALS_DIR_TOKEN } = require('../constants') | ||
@@ -15,3 +15,3 @@ /** | ||
* @param {String} target - The target of the include directive to resolve. | ||
* @param {File} file - The outermost virtual file from which the include originated (not | ||
* @param {File} page - The outermost virtual file from which the include originated (not | ||
* necessarily the current file). | ||
@@ -22,45 +22,50 @@ * @param {Cursor} cursor - The cursor of the reader for file that contains the include directive. | ||
*/ | ||
function resolveIncludeFile (target, file, cursor, catalog) { | ||
let [family, relative] = splitOnce(target, '/') | ||
if (family === PARTIALS_DIR_PROXY) { | ||
family = 'partial' | ||
} else if (family === EXAMPLES_DIR_PROXY) { | ||
family = 'example' | ||
function resolveIncludeFile (target, page, cursor, catalog) { | ||
const ctx = (cursor.file || {}).context || page.src | ||
let resolved | ||
let family | ||
let relative | ||
let placeholder | ||
if (~target.indexOf('$')) { | ||
if (target.startsWith(PARTIALS_DIR_TOKEN) || target.startsWith(EXAMPLES_DIR_TOKEN)) { | ||
;[family, relative] = splitOnce(target, '$') | ||
if (relative.charAt() === '/') { | ||
relative = relative.substr(1) | ||
placeholder = true | ||
} | ||
resolved = catalog.getById({ | ||
component: ctx.component, | ||
version: ctx.version, | ||
module: ctx.module, | ||
family, | ||
relative, | ||
}) | ||
} else { | ||
resolved = catalog.resolveResource(target, { component: ctx.component, version: ctx.version, module: ctx.module }) | ||
} | ||
} else { | ||
family = undefined | ||
relative = target | ||
} | ||
let resolvedIncludeFile | ||
if (family) { | ||
resolvedIncludeFile = catalog.getById({ | ||
component: file.src.component, | ||
version: file.src.version, | ||
module: file.src.module, | ||
family, | ||
relative, | ||
resolved = catalog.getByPath({ | ||
component: ctx.component, | ||
version: ctx.version, | ||
// QUESTION does cursor.dir always contain the value we expect? | ||
path: path.join(cursor.dir.toString(), target), | ||
}) | ||
} else { | ||
// TODO can we keep track of the virtual file we're currently in instead of relying on cursor.dir? | ||
resolvedIncludeFile = catalog.getByPath({ | ||
component: file.src.component, | ||
version: file.src.version, | ||
path: path.join(cursor.dir, relative), | ||
}) | ||
} | ||
if (resolvedIncludeFile) { | ||
if (resolved) { | ||
const resolvedSrc = resolved.src | ||
return { | ||
file: resolvedIncludeFile.src.path, | ||
path: resolvedIncludeFile.src.basename, | ||
// NOTE src.contents is set if a page is marked as a partial | ||
contents: (resolvedIncludeFile.src.contents || resolvedIncludeFile.contents).toString(), | ||
context: resolvedSrc, | ||
file: resolvedSrc.path, | ||
path: resolvedSrc.basename, | ||
// NOTE src.contents is set if page is marked as a partial | ||
// TODO if include file is a page, warn if not marked as a partial | ||
contents: (resolvedSrc.contents || resolved.contents).toString(), | ||
} | ||
} else { | ||
if (family) target = `{${family}sdir}/${relative}` | ||
// FIXME use replace next line instead of pushing an include; maybe raise error | ||
// TODO log "Unresolved include" | ||
return { | ||
context: cursor.dir.context, | ||
file: cursor.file, | ||
contents: `+include::${target}[]+`, | ||
contents: `+include::${placeholder ? '{' + family + 'sdir}/' + relative : target}[]+`, | ||
} | ||
@@ -67,0 +72,0 @@ } |
@@ -6,3 +6,3 @@ 'use strict' | ||
if ('encoding' in String.prototype && String(String.prototype.encoding) !== 'UTF-8') { | ||
String.prototype.encoding = Opal.const_get_local(Opal.const_get_qualified('::', 'Encoding'), 'UTF_8') // eslint-disable-line | ||
String.prototype.encoding = Opal.const_get_local(Opal.const_get_qualified('::', 'Encoding'), 'UTF_8') // eslint-disable-line no-extend-native | ||
} | ||
@@ -19,3 +19,3 @@ | ||
const DOT_RELATIVE_RX = new RegExp(`^\\.{1,2}[/${ospath.sep.replace('/', '').replace('\\', '\\\\')}]`) | ||
const { EXAMPLES_DIR_PROXY, PARTIALS_DIR_PROXY } = require('./constants') | ||
const { EXAMPLES_DIR_TOKEN, PARTIALS_DIR_TOKEN } = require('./constants') | ||
@@ -66,4 +66,4 @@ /** | ||
attachmentsdir: path.join(file.pub.moduleRootPath, '_attachments'), | ||
examplesdir: EXAMPLES_DIR_PROXY, | ||
partialsdir: PARTIALS_DIR_PROXY, | ||
examplesdir: EXAMPLES_DIR_TOKEN, | ||
partialsdir: PARTIALS_DIR_TOKEN, | ||
} | ||
@@ -70,0 +70,0 @@ const pageAttrs = fileSrc.family === 'page' ? computePageAttrs(fileSrc, contentCatalog) : {} |
{ | ||
"name": "@antora/asciidoc-loader", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Loads AsciiDoc content into an Asciidoctor Document object (AST) for use in an Antora documentation pipeline.", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24579
538