Inline Macro Processor Extension Example

Purpose

Replace the macro emoticon with the corresponding text emoticon.

sample-emoticon-doc.adoc

emoticon:wink[]
emoticon:grin[]
emoticon:x[]

EmoticonInlineMacroProcessor

emoticon-inline-macro-processor.js
module.exports = function (registry) {
  registry.inlineMacro('emoticon', function () {
    var self = this
    self.process(function (parent, target) {
      var text
      if (target === 'grin') {
        text = ':D'
      } else if (target === 'wink') {
        text = ';)'
      } else {
        text = ':)'
      }
      return self.createInline(parent, 'quoted', text, { 'type': 'strong' })
    })
  })
}

Usage

const asciidoctor = require('asciidoctor')()
const registry = asciidoctor.Extensions.create()
require('./emoticon-inline-macro-processor.js')(registry)

const html = asciidoctor.convertFile('ssample-emoticon-doc.adoc', { 'to_file': false, 'extension_registry': registry })
console.log(html)