diff --git a/antora-playbook.yml b/antora-playbook.yml index 35277ed..aabb5ae 100644 --- a/antora-playbook.yml +++ b/antora-playbook.yml @@ -35,6 +35,7 @@ asciidoc: page-pagination: '' extensions: - ./lib/feed-block-macro.js + - ./lib/javadoc-block-macro.js - ./lib/jetty-block.js - ./lib/skip-include-processor.js - ./lib/absolute-path-include-processor.js diff --git a/lib/javadoc-block-macro.js b/lib/javadoc-block-macro.js new file mode 100644 index 0000000..ef27e51 --- /dev/null +++ b/lib/javadoc-block-macro.js @@ -0,0 +1,53 @@ +'use strict' + +const toHash = (object) => object && !object.$$is_hash ? Opal.hash2(Object.keys(object), object) : object + +const toProc = (fn) => Object.defineProperty(fn, '$$arity', { value: fn.length }) + +function register (registry, context = {}) { + if (!(registry && context)) return // NOTE only works as scoped extension + registry.$groups().$store('javadoc', toProc(createExtensionGroup(context))) + return registry +} + +function createExtensionGroup ({ contentCatalog, file }) { + return function () { + this.blockMacro('javadoc', function () { + this.process((parent, target, attrs) => { + const doc = parent.getDocument() + const cursor = doc.getReader().$cursor_at_mark() + const ctx = (cursor.file || {}).src || file.src + const includeFile = contentCatalog.resolveResource(target, ctx, undefined, ['partial']) + if (!includeFile) return this.createParagraph(parent, `javadoc::${target}[]`, {}) + const rawLines = includeFile.contents.toString().split('\n') + const lines = [] + let capturing + for (let line of rawLines) { + if (capturing) { + if (line.endsWith('')) break + line = line.replace(/^ +[*](?: +|$)/, '') + if (line === '