asciidoctor.js icon indicating copy to clipboard operation
asciidoctor.js copied to clipboard

Provide an API to extend a built-in converter or syntax highlighter

Open ggrossetie opened this issue 4 years ago • 1 comments

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)

ggrossetie avatar Sep 11 '21 12:09 ggrossetie

The asciidoctor.klass.extend would also be useful when we register a converter using an instance.

ggrossetie avatar Dec 06 '21 07:12 ggrossetie