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 3.0.0-alpha.6 to 3.0.0-alpha.7

18

lib/converter/create.js
'use strict'
const Html5Converter = require('./html5')
const convertImageRef = require('./../image/convert-image-ref')
const convertPageRef = require('./../xref/convert-page-ref')
const defineHtml5Converter = require('./html5')

@@ -10,12 +12,16 @@ /**

*
* @param {Object} callbacks - Callback functions.
* @param {Function} callbacks.onImageRef - A function that converts an image reference.
* @param {Function} callbacks.onPageRef - A function that converts a page reference.
* @param {File} file - The virtual file whose contents is an AsciiDoc source document.
* @param {ContentCatalog} contentCatalog - The catalog of all virtual content files in the site.
* @param {Object} config - AsciiDoc processor configuration options.
*
* @returns {Converter} An enhanced instance of Asciidoctor's HTML5 converter.
*/
function createConverter (callbacks) {
return Html5Converter.$new('html5', undefined, callbacks)
function createConverter (file, contentCatalog, config) {
const relativizePageRefs = config.relativizePageRefs !== false
return defineHtml5Converter().$new('html5', undefined, {
onImageRef: (resourceSpec) => convertImageRef(resourceSpec, file, contentCatalog),
onPageRef: (pageSpec, content) => convertPageRef(pageSpec, content, file, contentCatalog, relativizePageRefs),
})
}
module.exports = createConverter

@@ -5,13 +5,21 @@ 'use strict'

const { $Antora } = require('../constants')
const $logger = Symbol('logger')
const $imageRefCallback = Symbol('imageRefCallback')
const $pageRefCallback = Symbol('pageRefCallback')
const $imageRefCallback = Symbol('imageRefCallback')
const converterFor = Opal.Asciidoctor.Converter.$for.bind(Opal.Asciidoctor.Converter)
const Html5Converter = (() => {
const scope = Opal.klass(
Opal.module(null, 'Antora', $Antora),
Opal.module(null, 'Asciidoctor').Converter.Html5Converter,
'Html5Converter'
)
let classDef
Opal.defn(scope, '$initialize', function initialize (backend, opts, callbacks) {
const defineHtml5Converter = () => {
const superclass = converterFor('html5')
if (classDef) {
if (classDef.$superclass() !== superclass) {
Object.setPrototypeOf(classDef.$$prototype, (classDef.$$super = superclass).$$prototype)
}
return classDef
}
classDef = Opal.klass(Opal.Antora || Opal.module(null, 'Antora', $Antora), superclass, 'Html5Converter')
Opal.defn(classDef, '$initialize', function initialize (backend, opts, callbacks) {
Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), [backend, opts])

@@ -22,3 +30,3 @@ this[$pageRefCallback] = callbacks.onPageRef

Opal.defn(scope, '$convert_inline_anchor', function convertInlineAnchor (node) {
Opal.defn(classDef, '$convert_inline_anchor', function convertInlineAnchor (node) {
if (node.getType() === 'xref') {

@@ -45,7 +53,16 @@ let callback

type = 'link'
attrs.role = `page${unresolved ? ' unresolved' : ''}${attrs.role ? ' ' + attrs.role : ''}`
if (unresolved) {
const logger = this[$logger] || (this[$logger] = this.$logger())
let msg = 'target of xref not found: ' + refSpec
const loc = node.getParent().getSourceLocation()
if (loc) msg = this.$message_with_context(msg, Opal.hash2(['source_location'], { source_location: loc }))
logger.error(msg)
attrs.role = `page unresolved${attrs.role ? ' ' + attrs.role : ''}`
} else {
attrs.role = `page${attrs.role ? ' ' + attrs.role : ''}`
}
}
const attributes = Opal.hash2(Object.keys(attrs), attrs)
const options = Opal.hash2(['type', 'target', 'attributes'], { type, target, attributes })
node = Opal.module(null, 'Asciidoctor').Inline.$new(node.getParent(), 'anchor', content, options)
node = Opal.Asciidoctor.Inline.$new(node.getParent(), 'anchor', content, options)
}

@@ -56,3 +73,3 @@ }

Opal.defn(scope, '$convert_image', function convertImage (node) {
Opal.defn(classDef, '$convert_image', function convertImage (node) {
return Opal.send(this, Opal.find_super_dispatcher(this, 'convert_image', convertImage), [

@@ -63,3 +80,3 @@ transformImageNode(this, node, node.getAttribute('target')),

Opal.defn(scope, '$convert_inline_image', function convertInlineImage (node) {
Opal.defn(classDef, '$convert_inline_image', function convertInlineImage (node) {
return Opal.send(this, Opal.find_super_dispatcher(this, 'convert_inline_image', convertInlineImage), [

@@ -70,4 +87,4 @@ transformImageNode(this, node, node.getTarget()),

return scope
})()
return classDef
}

@@ -106,2 +123,2 @@ function transformImageNode (converter, node, imageTarget) {

module.exports = Html5Converter
module.exports = defineHtml5Converter
'use strict'
const Opal = global.Opal
const { $Antora } = require('../constants')
const DBL_COLON = '::'
const DBL_SQUARE = '[]'
const NEWLINE_RX = /\r\n?|\n/

@@ -14,6 +13,9 @@ const TAG_DIRECTIVE_RX = /\b(?:tag|(e)nd)::(\S+?)\[\](?=$|[ \r])/m

const $callback = Symbol('callback')
const superclass = Opal.module(null, 'Asciidoctor').Extensions.IncludeProcessor
const scope = Opal.klass(Opal.module(null, 'Antora', $Antora), superclass, 'IncludeProcessor')
const classDef = Opal.klass(
Opal.Antora || Opal.module(null, 'Antora', $Antora),
Opal.Asciidoctor.Extensions.IncludeProcessor,
'IncludeProcessor'
)
Opal.defn(scope, '$initialize', function initialize (callback) {
Opal.defn(classDef, '$initialize', function initialize (callback) {
Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize))

@@ -23,3 +25,3 @@ this[$callback] = callback

Opal.defn(scope, '$process', function (doc, reader, target, attrs) {
Opal.defn(classDef, '$process', function (doc, reader, target, attrs) {
if (reader.maxdepth === Opal.nil) return

@@ -56,3 +58,3 @@ const sourceCursor = reader.$cursor_at_prev_line()

} else {
log('error', `include target not found: ${target}`, reader, sourceCursor)
log('error', `target of include not found: ${target}`, reader, sourceCursor)
reader.$unshift(`Unresolved include directive in ${sourceCursor.file} - include::${target}[]`)

@@ -63,3 +65,3 @@ }

return scope
return classDef
})()

@@ -144,24 +146,24 @@

function filterLinesByTags (reader, target, file, tags, sourceCursor) {
let selecting, selectingDefault, wildcard
if (tags.has('**')) {
if (tags.has('*')) {
selectingDefault = selecting = tags.get('**')
wildcard = tags.get('*')
let selectingDefault, selecting, wildcard
const globstar = tags.get('**')
const star = tags.get('*')
if (globstar === undefined) {
if (star === undefined) {
selectingDefault = selecting = !mapContainsValue(tags, true)
} else {
if ((wildcard = star) || tags.keys().next().value !== '*') {
selectingDefault = selecting = false
} else {
selectingDefault = selecting = !wildcard
}
tags.delete('*')
} else {
selectingDefault = selecting = wildcard = tags.get('**')
}
} else {
tags.delete('**')
} else {
selecting = true
for (const v of tags.values()) {
if (v === selecting) {
selecting = false
break
}
}
selectingDefault = selecting
if (tags.has('*')) {
wildcard = tags.get('*')
selectingDefault = selecting = globstar
if (star === undefined) {
if (!globstar && tags.values().next().value === false) wildcard = true
} else {
tags.delete('*')
wildcard = star
}

@@ -259,2 +261,8 @@ }

function mapContainsValue (map, value) {
for (const v of map.values()) {
if (v === value) return true
}
}
module.exports = IncludeProcessor

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

/**
* Resolves the specified include target to a virtual file in the content catalog.
* Resolves the specified target of an include directive to a virtual file in the content catalog.
*

@@ -13,0 +13,0 @@ * @memberof asciidoc-loader

@@ -6,4 +6,2 @@ 'use strict'

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

@@ -71,2 +69,3 @@ const createExtensionRegistry = require('./create-extension-registry')

if (config.doctype) opts.doctype = config.doctype
if (config.sourcemap) opts.sourcemap = true
let contents = file.contents

@@ -82,9 +81,4 @@ if (config.headerOnly) {

} else if (contentCatalog) {
// NOTE relfilesuffix must be set for page-to-page xrefs to work correctly
attributes.relfilesuffix = '.adoc'
const relativizePageRefs = config.relativizePageRefs !== false
opts.converter = createConverter({
onImageRef: (resourceSpec) => convertImageRef(resourceSpec, file, contentCatalog),
onPageRef: (pageSpec, content) => convertPageRef(pageSpec, content, file, contentCatalog, relativizePageRefs),
})
attributes.relfilesuffix = '.adoc' // NOTE relfilesuffix must be set for page-to-page xrefs to work correctly
opts.converter = createConverter(file, contentCatalog, config)
}

@@ -220,4 +214,3 @@ const doc = asciidoctor.load(contents.toString(), opts)

resolveAsciiDocConfig,
// @deprecated scheduled to be removed in Antora 4
resolveConfig: resolveAsciiDocConfig,
resolveConfig: resolveAsciiDocConfig, // @deprecated scheduled to be removed in Antora 4
})

@@ -9,7 +9,3 @@ 'use strict'

const LoggerAdapter = (() => {
const scope = Opal.klass(
Opal.module(null, 'Antora', $Antora),
Opal.const_get_qualified('::', 'Logger'),
'LoggerAdapter'
)
const classDef = Opal.klass(Opal.Antora || Opal.module(null, 'Antora', $Antora), Opal.Logger, 'LoggerAdapter')

@@ -33,5 +29,5 @@ const severityMap = ((Severity) =>

)
))(scope.$superclass().Severity)
))(classDef.$superclass().Severity)
Opal.defn(scope, '$initialize', function initialize (context) {
Opal.defn(classDef, '$initialize', function initialize (context) {
Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), [Opal.nil])

@@ -45,3 +41,3 @@ const delegate = logger.unwrap()

Opal.defn(scope, '$add', function add (severity, message, progname) {
Opal.defn(classDef, '$add', function add (severity, message, progname) {
if (severity < this.level) {

@@ -91,5 +87,5 @@ if (severity >= this.failureLevel) this.delegate.setFailOnExit()

return scope
return classDef
})()
module.exports = Object.assign(LoggerAdapter, { logger })

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

if (!((targetPage = contentCatalog.resolvePage(pageSpec, currentPage.src)) && targetPage.pub)) {
// TODO log "Unresolved page ID" if undefined or "Invalid page ID syntax" if false
return { content: content || refSpec, target: '#' + refSpec, unresolved: true }

@@ -42,0 +41,0 @@ }

{
"name": "@antora/asciidoc-loader",
"version": "3.0.0-alpha.6",
"version": "3.0.0-alpha.7",
"description": "Loads AsciiDoc content into an Asciidoctor Document object (AST) for use in an Antora documentation pipeline.",

@@ -20,3 +20,3 @@ "license": "MPL-2.0",

"dependencies": {
"@antora/logger": "3.0.0-alpha.6",
"@antora/logger": "3.0.0-alpha.7",
"@asciidoctor/core": "~2.2"

@@ -39,3 +39,3 @@ },

],
"gitHead": "38ec002e88eede3ce5c401a6e226d1a0356945c5"
"gitHead": "fbd597b3680474f2083cda8a7facf1e2848c08e0"
}
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