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

Reusing extensions registry doesn't work in v3.0.2 #1709

Open
saneef opened this issue Jul 22, 2023 · 4 comments
Open

Reusing extensions registry doesn't work in v3.0.2 #1709

saneef opened this issue Jul 22, 2023 · 4 comments

Comments

@saneef
Copy link

saneef commented Jul 22, 2023

When I reuse an registry, in subsequent calls to convert(), the registered extensions don't work.

See the sample code, which is based on an example from docs:

const asciidoctor = require("asciidoctor")();
const registry = asciidoctor.Extensions.create();
registry.block(function () {
  var self = this;
  self.named("shout");
  self.onContext("paragraph");
  self.process(function (parent, reader) {
    var lines = reader.getLines().map(function (l) {
      return l.toUpperCase();
    });
    return self.createBlock(parent, "paragraph", lines);
  });
});

const text = `[shout]\
\nSay it loud.\
\nSay it proud.`;

// 1
const htmlA = asciidoctor.convert(text, {
  extension_registry: registry,
});

// 2
const htmlB = asciidoctor.convert(text, {
  extension_registry: registry,
});

console.log(`Converted first:
${htmlA}`);
console.log(" ");
console.log(`Converted second:
${htmlB}`);

// 🚨 Output from v3.0.2
// Converted first:
// <div class="paragraph">
// <p>SAY IT LOUD.
// SAY IT PROUD.</p>
// </div>

// Converted second:
// <div class="paragraph">
// <p>Say it loud.
// Say it proud.</p>
// </div>

// ✅ Output from v2.2.6
// Converted first:
// <div class="paragraph">
// <p>SAY IT LOUD.
// SAY IT PROUD.</p>
// </div>

// Converted second:
// <div class="paragraph">
// <p>SAY IT LOUD.
// SAY IT PROUD.</p>
// </div>

The same code works fine in v2.2.x.

Is this a bug, or am I doing something wrong?

I encountered this issue when I was trying to find a fix for saneef/eleventy-plugin-asciidoc#10.

@ggrossetie
Copy link
Member

@mojavelinux I vaguely remember a discussion about it but I don't recall what needs to be done? Does that ring a bell?

@saneef
Copy link
Author

saneef commented Feb 12, 2024

Based on this comment, I reworked the plugin in which I'm using asciidoctor.js. Now I'm creating new registry for each call to convert()

Should we close this issue? May we should add a note in documentation.

@ggrossetie
Copy link
Member

Based on asciidoctor/asciidoctor-kroki#421 (comment), I reworked the plugin in which I'm using asciidoctor.js. Now I'm creating new registry for each call to convert()

Thanks that's the comment I was looking for!

Should we close this issue? May we should add a note in documentation.

Yes, we should add a callout/admonition in: https://docs.asciidoctor.org/asciidoctor.js/latest/extend/extensions/register/

@mojavelinux
Copy link
Member

I vaguely remember a discussion about it but I don't recall what needs to be done? Does that ring a bell?

I think you're referring to asciidoctor/asciidoctor#4256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants