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
module.exports = function (registry) {
  registry.block(function () {
    var self = this
    self.named('shout')
    self.onContext('paragraph')
    self.process(function (parent, reader) {
      var lines = reader.getLines().map(function (l) { return l.toUpperCase() })
      return self.createBlock(parent, 'paragraph', lines)
    })
  })
}

Usage

const asciidoctor = require('asciidoctor')()
const registry = asciidoctor.Extensions.create()
require('./shout-block.js')(registry)

const html = asciidoctor.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>