asciidoctor.js
asciidoctor.js copied to clipboard
Provide an API to extend a built-in converter or syntax highlighter
Currently, Asciidoctor.js does not provide an API to extend a class. As a result, we need to use Opal low-level API to do so.
We could introduce a third argument on the SyntaxHighlighter.register function:
class CustomHighlightJsAdapter {
docinfo (location) {
// ...
}
}
asciidoctor.SyntaxHighlighter.register(
// names
['highlight.js', 'highlightjs'],
// syntax highligther
CustomHighlightJsAdapter,
// extends
asciidoctor.SyntaxHighlighter.for('highlight.js')
)
Or introduce a generic function:
class CustomHighlightJsAdapter {
docinfo (location) {
// ...
}
}
asciidoctor.klass.extend(CustomHighlightJsAdapter, asciidoctor.SyntaxHighlighter.for('highlight.js'))
asciidoctor.SyntaxHighlighter.register(['highlight.js', 'highlightjs'], CustomHighlightJsAdapter)
The asciidoctor.klass.extend would also be useful when we register a converter using an instance.