Inline Macro Processor Extension Example
- Purpose
-
Replace the macro
emoticonwith the corresponding text emoticon.
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)