Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to register asciidoctor extensions #10

Closed
tbroyer opened this issue Jul 21, 2023 · 5 comments
Closed

Impossible to register asciidoctor extensions #10

tbroyer opened this issue Jul 21, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@tbroyer
Copy link

tbroyer commented Jul 21, 2023

With version 2.0.0 of the plugin, it was possible to register asciidoctor extensions using code like:

const eleventyAsciidoc = require("eleventy-plugin-asciidoc");

const asciidoctor = require("asciidoctor").default();
const registry = asciidoctor.Extensions.create();
require("./my-extension.js")(registry);

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(eleventyAsciidoc, {
    extension_registry: registry,
  });
};

This no longer works with version 3.

I suppose it comes from upstream Asciidoctor.js changes that now requires the registry to have been created from the same asciidoctor instance; anyway, we cannot update to version 3 due to that change, and I'd suggest providing a proper and future-proof way to register asciidoctor extensions in the plugin: a callback function passed in the options that the plugin would call (if present) with an extension registry (or with the asciidoctor.Extensions object directly).

From the user point of view, it would be used as:

const eleventyAsciidoc = require("eleventy-plugin-asciidoc");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(eleventyAsciidoc, {
    register_extensions(registry) {
      require("./my-extension.js")(registry);
    },
  });
};

And from inside the plugin, it could be along the lines of:

const { register_extensions, ...options } = eleventyOptions;

if (register_extensions) {
  const registry = processor.Extensions.create();
  register_extensions(registry);
  options.extension_registry = registry;
}
@saneef
Copy link
Owner

saneef commented Jul 22, 2023

Thank you, @tbroyer, for reporting. I'll look into it.

@saneef
Copy link
Owner

saneef commented Jul 22, 2023

@tbroyer To me, it looks like a problem with the latest asciidoctor.js. Our existing way of registering extension works with the first call of convert(), but not with the subsequent calls. 😞 See my comments on asciidoctor/asciidoctor.js#1709

Let's wait for their reply.

@tbroyer
Copy link
Author

tbroyer commented Jul 27, 2023

Fwiw, from a related issue: asciidoctor/asciidoctor-kroki#421 (comment)

A registry is not really designed to be reused. Ideally, it should be created per conversion.

It looks like providing a function in the options is not that bad an idea actually.
IIUC, you could either give it once to asciidoctor.Extensions.register(), or call it once per conversion each time with a new registry.

@saneef
Copy link
Owner

saneef commented Jul 27, 2023

Yup! I saw that comment. TBH, I was hoping there might be some fix from their side. 😄 I have seen our current approach being used in other projects. Now many of those need to be changed to re-create the registry for each conversion.

Having said that, I'll work on the approach, like you have suggested, using a function which gets a new registry for each conversion. I had tried asciidoctor.Extensions.register(), but it didn't work for me.

Will make a new release in a couple of days.

saneef added a commit that referenced this issue Jul 27, 2023
This can be use instead of Asciidoctor's 'extension_registry' option.
'configure_extension_registry' will create new registry for each file
conversion.

Fixes #10
@saneef saneef closed this as completed in a4e13a2 Jul 28, 2023
@saneef
Copy link
Owner

saneef commented Jul 28, 2023

I have published a new release, v3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants