asciidoctor / asciidoctor-reveal.js

:crystal_ball: A reveal.js converter for Asciidoctor and Asciidoctor.js. Write your slides in AsciiDoc!
http://asciidoctor.org
Other
289 stars 188 forks source link

Activating Reveal.js Extensions only for Reveal.js backend #489

Open rahmanusta opened 1 year ago

rahmanusta commented 1 year ago

Hello,

In AsciidocFX, I use AsciidoctorJ to construct a certain number of Asciidoctor instances and load all required libraries all at once. I recently discovered that the highlight js numbering extension registers itself even though that the backend is HTML5. I assumed the asciidoctor-* libraries were isolated from each other if they targeted a specific backend. I think the library should not interfere with the other backends. May it be possible to activate Reveal's highlight.js extension only if the backend is reveal.js ?

https://github.com/asciidoctor/asciidoctor-reveal.js/blob/93b307304f8e132e3f13403c94a9ea010891b859/lib/asciidoctor-revealjs/highlightjs.rb#L6

ggrossetie commented 1 year ago

Hey!

It might be possible to conditionally call SyntaxHighlighter.register instead of using:

https://github.com/asciidoctor/asciidoctor-reveal.js/blob/93b307304f8e132e3f13403c94a9ea010891b859/lib/asciidoctor-revealjs/highlightjs.rb#L7

However, I'm not really sure how/when we should call it since the SyntaxHighlighter registry is a singleton so I don't think you can have more than one instance.

We could potentially use the backend argument in the constructor to delegate or not to the built-in Highlight.js syntax highlighter when the backend is html5 or revealjs:

https://github.com/asciidoctor/asciidoctor/blob/40bc23cbc105d87ce25892d4c1866fad7f9ba01a/lib/asciidoctor/syntax_highlighter.rb#L19

In other words, the highlight.js adapter (from this converter) will still override the built-in highlight.js syntax highlighter in the registry but use the built-in when the backend is not revealjs. What do you think?