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

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
export default function (registry) {
  registry.inlineMacro('emoticon', function () {
    const self = this
    self.process(function (parent, target) {
      let text
      if (target === 'grin') {
        text = ':D'
      } else if (target === 'wink') {
        text = ';)'
      } else {
        text = ':)'
      }
      return self.createInline(parent, 'quoted', text, { type: 'strong' })
    })
  })
}

Usage

import { Extensions, convertFile } from '@asciidoctor/core'
import registerEmoticonInlineMacro from './emoticon-inline-macro-processor.js'

const registry = Extensions.create()
registerEmoticonInlineMacro(registry)

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