Include Processor Extension Example

Purpose

Return the content "foo" if the file extension of the include directive target is "foo".

sample-foo-doc.adoc

include::./test.foo[]

FooIncludeProcessor

foo-include-processor.js
module.exports = function (registry) {
  registry.includeProcessor(function () {
    var self = this
    self.handles(function (target) {
      return target.endsWith('.foo')
    })
    self.process(function (doc, reader, target, attrs) {
      var content = ['foo']
      return reader.pushInclude(content, target, target, 1, attrs)
    })
  })
}

Usage

const asciidoctor = require('asciidoctor')()
const registry = asciidoctor.Extensions.create()
require('./foo-include-processor.js')(registry)

const html = asciidoctor.convert('include::./test.foo[]', { extension_registry: registry })
console.log(html)
// <div class="paragraph">
// <p>foo</p>
// </div