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

Tree Processor Extension Example

Purpose

Make the document GDPR compliant by replacing the first block (paragraph) with the sentence "GDPR compliant :)"

sample-gdpr-doc.adoc

= Privacy agreement

We track you for your own safety!

GDPRTreeProcessor

gdpr-tree-processor.js
export default function (registry) {
  registry.treeProcessor(function () {
    const self = this
    self.process(function (doc) {
      doc.getBlocks()[0] = self.createBlock(doc, 'paragraph', 'GDPR compliant :)')
      return doc
    })
  })
}

Usage

import { Extensions, convertFile } from '@asciidoctor/core'
import registerGdprTreeProcessor from './gdpr-tree-processor.js'

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

const doc = await convertFile('sample-gdpr-doc.adoc', { extension_registry: registry })
console.log(doc.getBlocks()[0].getSource()) // 'GDPR compliant :)'