树处理器扩展示例
- 目的
-
通过将文档的第一个块(段落)替换为句子 "GDPR compliant :)",使文档符合 GDPR 要求。
GDPRTreeProcessor
gdpr-tree-processor.js
module.exports = function (registry) {
registry.treeProcessor(function () {
var self = this
self.process(function (doc) {
doc.getBlocks()[0] = self.createBlock(doc, 'paragraph', 'GDPR compliant :)')
return doc
})
})
}
使用
const asciidoctor = require('asciidoctor')()
const registry = asciidoctor.Extensions.create()
require('./gdpr-tree-processor.js')(registry)
const doc = asciidoctor.convertFile('sample-gdpr-doc.adoc', { 'extension_registry': registry })
console.log(doc.getBlocks()[0].getSource()) // 'GDPR compliant :)'