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

Block Extension Example

Purpose

Capitalize the text in a shout block paragraph as if the author was yelling!

sample-shout-doc.adoc

[shout]
Say it loud.
Say it proud.

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>