Skip to content

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

@saneef

Description

@saneef

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions