This documentation covers a prerelease version of the software. Follow this link to view the documentation for the stable version (3.0) instead.

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
export default function (registry) {
  registry.includeProcessor(function () {
    const self = this
    self.handles(function (target) {
      return target.endsWith('.foo')
    })
    self.process(function (doc, reader, target, attrs) {
      const content = ['foo']
      return reader.pushInclude(content, target, target, 1, attrs)
    })
  })
}

Usage

import { Extensions, convert } from '@asciidoctor/core'
import registerFooIncludeProcessor from './foo-include-processor.js'

const registry = Extensions.create()
registerFooIncludeProcessor(registry)

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