asciidoctor / asciidoctor.js

:scroll: A JavaScript port of Asciidoctor, a modern implementation of AsciiDoc
https://asciidoctor.org
MIT License
740 stars 136 forks source link

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

Open ggrossetie opened 3 years ago

ggrossetie commented 3 years ago

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 commented 2 years ago

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