Socket
Socket
Sign inDemoInstall

@antora/asciidoc-loader

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/asciidoc-loader - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0-rc.1

lib/image/convert-image-ref.js

68

lib/converter/html5.js

@@ -5,3 +5,4 @@ 'use strict'

const { $Antora } = require('../constants')
const $pageRefCallback = Symbol('callback')
const $pageRefCallback = Symbol('pageRefCallback')
const $imageRefCallback = Symbol('imageRefCallback')

@@ -18,32 +19,55 @@ const Html5Converter = (() => {

this[$pageRefCallback] = callbacks.onPageRef
this[$imageRefCallback] = callbacks.onImageRef
})
Opal.defn(scope, '$inline_anchor', function inlineAnchor (node) {
Opal.defn(scope, '$inline_anchor', function convertInlineAnchor (node) {
if (node.getType() === 'xref') {
if (node.getAttribute('path')) {
const callback = this[$pageRefCallback]
if (callback) {
const attrs = node.getAttributes()
if (attrs.fragment === Opal.nil) delete attrs.fragment
const { content, target } = callback(attrs.refid, node.getText())
let options
// NOTE if resolved target starts with #, it's an unresolved xref
if (target.charAt() === '#') {
options = Opal.hash2(['type', 'target'], { type: 'link', target })
} else {
attrs.role = attrs.role ? 'page ' + attrs.role : 'page'
options = Opal.hash2(['type', 'target', 'attrs'], {
type: 'link',
target,
attributes: Opal.hash2(Object.keys(attrs), attrs),
})
}
node = Opal.module(null, 'Asciidoctor').Inline.$new(node.getParent(), 'anchor', content, options)
let callback
if (node.getAttribute('path') && (callback = this[$pageRefCallback])) {
const attrs = node.getAttributes()
if (attrs.fragment === Opal.nil) delete attrs.fragment
const { content, target, internal, unresolved } = callback(attrs.refid, node.getText())
let options
if (internal) {
// QUESTION should we propogate the role in this case?
options = Opal.hash2(['type', 'target'], { type: 'link', target })
} else {
attrs.role = `page${unresolved ? ' unresolved' : ''}${attrs.role ? ' ' + attrs.role : ''}`
options = Opal.hash2(['type', 'target', 'attrs'], {
type: 'link',
target,
attributes: Opal.hash2(Object.keys(attrs), attrs),
})
}
node = Opal.module(null, 'Asciidoctor').Inline.$new(node.getParent(), 'anchor', content, options)
}
}
return Opal.send(this, Opal.find_super_dispatcher(this, 'inline_anchor', inlineAnchor), [node])
return Opal.send(this, Opal.find_super_dispatcher(this, 'inline_anchor', convertInlineAnchor), [node])
})
Opal.defn(scope, '$image', function convertImage (node) {
let callback
if (matchesResourceSpec(node.getAttribute('target')) && (callback = this[$imageRefCallback])) {
const attrs = node.getAttributes()
if (attrs.alt === attrs['default-alt']) node.setAttribute('alt', attrs.alt.split(/[@:]/).pop())
Opal.defs(node, '$image_uri', (imageSpec) => callback(imageSpec) || imageSpec)
}
return Opal.send(this, Opal.find_super_dispatcher(this, 'image', convertImage), [node])
})
Opal.defn(scope, '$inline_image', function convertInlineImage (node) {
let callback
if (matchesResourceSpec(node.target) && (callback = this[$imageRefCallback])) {
const attrs = node.getAttributes()
if (attrs.alt === attrs['default-alt']) node.setAttribute('alt', attrs.alt.split(/[@:]/).pop())
Opal.defs(node, '$image_uri', (imageSpec) => callback(imageSpec) || imageSpec)
}
return Opal.send(this, Opal.find_super_dispatcher(this, 'inline_image', convertInlineImage), [node])
})
return scope
})()
function matchesResourceSpec (target) {
return ~target.indexOf(':')
? !(~target.indexOf('://') || (target.startsWith('data:') && ~target.indexOf(',')))
: target.indexOf('@') > 0
}
module.exports = Html5Converter

@@ -23,3 +23,3 @@ 'use strict'

Opal.defn(scope, '$process', function (doc, reader, target, attrs) {
if (reader.include_stack.length >= Opal.hash_get(reader.maxdepth, 'abs')) {
if (reader.$include_depth() >= Opal.hash_get(reader.maxdepth, 'abs')) {
if (Opal.hash_get(reader.maxdepth, 'abs')) {

@@ -26,0 +26,0 @@ log('error', `maximum include depth of ${Opal.hash_get(reader.maxdepth, 'rel')} exceeded`, reader)

@@ -11,2 +11,3 @@ 'use strict'

const Extensions = asciidoctor.Extensions
const convertImageRef = require('./image/convert-image-ref')
const convertPageRef = require('./xref/convert-page-ref')

@@ -45,6 +46,6 @@ const createConverter = require('./converter/create')

const fileSrc = file.src
const { family, relative } = fileSrc
const relative = fileSrc.relative
const extname = fileSrc.extname || relative.replace(/.*(?=\.)/g, '')
const intrinsicAttrs = {
docname: (family === 'nav' ? 'nav$' : '') + relative.substr(0, relative.length - extname.length),
docname: (fileSrc.family === 'nav' ? 'nav$' : '') + relative.substr(0, relative.length - extname.length),
docfile: file.path,

@@ -59,7 +60,8 @@ // NOTE docdir implicitly sets base_dir on document; Opal only expands value to absolute path if it starts with ./

}
const pageAttrs = family === 'page' ? computePageAttrs(fileSrc, contentCatalog) : undefined
const pageAttrs = computePageAttrs(fileSrc, contentCatalog)
const attributes = Object.assign({}, config.attributes, intrinsicAttrs, pageAttrs)
const relativizePageRefs = config.relativizePageRefs !== false
const converter = createConverter({
onPageRef: (refSpec, content) => convertPageRef(refSpec, content, file, contentCatalog, relativizePageRefs),
onImageRef: (resourceSpec) => convertImageRef(resourceSpec, file, contentCatalog),
onPageRef: (pageSpec, content) => convertPageRef(pageSpec, content, file, contentCatalog, relativizePageRefs),
})

@@ -86,3 +88,6 @@ const extensionRegistry = createExtensionRegistry(asciidoctor, {

const component = contentCatalog && contentCatalog.getComponent(fileSrc.component)
if (component) attrs['page-component-title'] = component.title
if (component) {
attrs['page-component-display-version'] = component.displayVersion
attrs['page-component-title'] = component.title
}
attrs['page-module'] = fileSrc.module

@@ -89,0 +94,0 @@ attrs['page-relative'] = fileSrc.relative

@@ -7,12 +7,14 @@ 'use strict'

/**
* Converts the specified page reference to an HTML link.
* Converts the specified page reference to the data necessary to build an HTML link.
*
* Parses the page reference (page ID and optional fragment), resolves the corresponding file from
* the content catalog, then grabs its publication (root-relative) path. If the relativize param is
* true, resolves the root relative path to a path relative to the URL of the current page. Uses the
* resulting path to create an HTML link pointing to the published target page.
* true, transforms the root-relative path to a relative path from the current page to the target
* page. Uses the resulting path to create the href for an HTML link that points to the published
* target page.
*
* @memberof asciidoc-loader
*
* @param {String} refSpec - The target of the xref macro that specifies a page reference.
* @param {String} refSpec - The target of an xref macro to a page, which is a page ID spec without
* the .adoc extension and with an optional fragment identifier.
* @param {String} content - The content (i.e., formatted text) of the link (undefined if not specified).

@@ -22,3 +24,5 @@ * @param {File} currentPage - The virtual file for the current page.

* @param {Boolean} [relativize=true] - Compute the target relative to the current page.
* @returns {Object} A map ({ content, target }) with the resolved content and target to make an HTML link.
* @returns {Object} A map ({ content, target, internal, unresolved }) containing the resolved
* content and target to make an HTML link, and hints to indicate if the reference is either
* internal or unresolved.
*/

@@ -28,24 +32,23 @@ function convertPageRef (refSpec, content, currentPage, contentCatalog, relativize = true) {

const [pageIdSpec, fragment] = splitOnce(refSpec, '#')
const hash = fragment ? '#' + fragment : ''
try {
if (!((targetPage = contentCatalog.resolvePage(pageIdSpec, currentPage.src)) && targetPage.pub)) {
// TODO log "Unresolved page ID"
return { content: `${pageIdSpec}.adoc${fragment ? '#' + fragment : ''}`, target: '#' }
return { content, target: `#${pageIdSpec}.adoc${hash}`, unresolved: true }
}
} catch (e) {
// TODO log "Invalid page ID syntax" (or e.message)
return { content: refSpec, target: '#' }
return { content, target: `#${refSpec}`, unresolved: true }
}
const hash = fragment ? '#' + fragment : ''
let target
let internal
if (relativize) {
target = computeRelativeUrlPath(currentPage.pub.url, targetPage.pub.url, hash)
if (target === hash) internal = true
} else {
target = targetPage.pub.url + hash
}
if (!content) content = `${pageIdSpec}.adoc${hash}`
return { content, target }
return { content: content || `${pageIdSpec}.adoc${hash}`, target, internal }
}
module.exports = convertPageRef
{
"name": "@antora/asciidoc-loader",
"version": "2.0.1",
"version": "2.1.0-rc.1",
"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",

@@ -19,4 +19,4 @@ # Antora AsciiDoc Loader

Copyright (C) 2017-2018 [OpenDevise Inc.](https://opendevise.com) and the [Antora Project](https://antora.org).
Copyright (C) 2017-2019 [OpenDevise Inc.](https://opendevise.com) and the [Antora Project](https://antora.org).
Use of this software is granted under the terms of the [Mozilla Public License Version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) (MPL-2.0).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc