Block Extension Example
- Purpose
-
Capitalize the text in a
shoutblock paragraph as if the author was yelling!
ShoutBlock
shout-block.js
export default function (registry) {
registry.block(function () {
const self = this
self.named('shout')
self.onContext('paragraph')
self.process(function (parent, reader) {
const lines = reader.getLines().map(l => l.toUpperCase())
return self.createBlock(parent, 'paragraph', lines)
})
})
}
Usage
import { Extensions, convertFile } from '@asciidoctor/core'
import registerShoutBlock from './shout-block.js'
const registry = Extensions.create()
registerShoutBlock(registry)
const html = await convertFile('sample-shout-doc.adoc', { to_file: false, extension_registry: registry })
console.log(html)
// <div class="paragraph">
// <p>SAY IT LOUD.
// SAY IT PROUD.</p>
// </div>