From 3baacb14ed3c69b4db435389ad8982eeb71a1801 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sep 25 2018 09:17:41 +0000 Subject: add the package inline macro for making package links --- diff --git a/lib/extensions/package-inline-macro.js b/lib/extensions/package-inline-macro.js new file mode 100644 index 0000000..44a1d39 --- /dev/null +++ b/lib/extensions/package-inline-macro.js @@ -0,0 +1,39 @@ +const DEFAULT_PACKAGE_URL_FORMAT = 'https://apps.fedoraproject.org/packages/%s' + +/** + * Adds an AsciiDoc inline macro named package that provides a shorthand syntax for linking to the + * page on Fedora apps for the specified Fedora package. + * + * This macro produces links that use the base URL https://apps.fedoraproject.org/packages by + * default. That URL can be overridden by defining the document attribute named + * uri-package-url-format. The %s token in the value of that attribute gets replaced by the name of + * the package. + * + * Example: + * + * package:asciidoctor[] + * + * @author Dan Allen + */ +const PackageInlineMacro = (() => { + const superclass = Opal.module(null, 'Asciidoctor').Extensions.InlineMacroProcessor + const scope = Opal.klass(Opal.module(null, 'Antora'), superclass, 'PackageInlineMacro', function () {}) + + Opal.defn(scope, '$initialize', function initialize (name, config) { + Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), [name, config]) + }) + + Opal.defn(scope, '$process', function (parent, target, attrs) { + const format = parent.getDocument().getAttribute('url-package-url-format', DEFAULT_PACKAGE_URL_FORMAT) + const url = format.replace('%s', target) + const content = target + const attributes = Opal.hash2(['window'], { window: '_blank' }) + return this.createInline(parent, 'anchor', content, { type: 'link', target: url, attributes }) + }) + + return scope +})() + +module.exports.register = (registry) => { + registry.inlineMacro(PackageInlineMacro.$new('package', Opal.hash())) +} diff --git a/site.yml b/site.yml index 2e8ead3..e2d1722 100644 --- a/site.yml +++ b/site.yml @@ -96,3 +96,6 @@ output: runtime: pull: true cache_dir: ./cache +asciidoc: + extensions: + - ./lib/extensions/package-inline-macro.js