asciidoctor / asciidoctor-browser-extension

:white_circle: An extension for web browsers that converts AsciiDoc files to HTML using Asciidoctor.js.
https://chrome.google.com/webstore/detail/asciidoctorjs-live-previe/iaalpfgpbocpdfblpnhhgllgbdbchmia
MIT License
216 stars 53 forks source link

Add Ruby-based extension in Asciidoctor.js Live Preview #297

Open habibessoussi opened 4 years ago

habibessoussi commented 4 years ago

In Asciidoctor.js Live Preview there is no way to add custom ruby-based extension. Along with Custom attributes it would be nice to add paths to rb extension files.

ggrossetie commented 4 years ago

Unfortunately Ruby-based extension cannot be used as-is in a JavaScript environment. You can transpile them to JavaScript using Opal or write them directly in JavaScript using Asciidoctor.js: https://asciidoctor-docs.netlify.com/asciidoctor.js/extend/extensions/

Out of curiosity which Ruby-based extension do you want to use ?

habibessoussi commented 4 years ago

Thanks a lot for your answer. It would be for BlockMacroProcessor extension

ggrossetie commented 4 years ago

Thanks a lot for your answer

You're welcome 😄

It would be for BlockMacroProcessor extension

Which one specifically ? I suppose that the extension already exists and is written in Ruby right ?

habibessoussi commented 4 years ago

No they are specific ones I created through extending this Ruby class. I will try to rewrite them in JavaScript

Dedeou31 commented 4 years ago

Hello I need to activate macro in browser I have migrated Ruby BlockMacro into Javascript using Opal by following herafter guidelines https://github.com/asciidoctor/asciidoctor.js/blob/master/docs/modules/extend/pages/extensions/compile-ruby-extension.adoc

But when I add the rendered javascript to the option of "Asciidoctor.js live preview" the Live preview isn't updated with macro treatment due to error : ReferenceError : Opal not found.

Do we have to add a require or something ?

ggrossetie commented 4 years ago

I think Opal is not found because the script is not executed in the same context, see: https://github.com/asciidoctor/asciidoctor-browser-extension/issues/220

I didn't have time to dig further on this issue... apparently there's a polyfill for Chrome...

Dedeou31 commented 4 years ago

Thanks for your quick answer. ;-) Do we have any workaround ? like including full opal.js script in extension generated script or something else ?