Tree Processor Extension Example
- Purpose
-
Make the document GDPR compliant by replacing the first block (paragraph) with the sentence "GDPR compliant :)"
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 :)'