Login  Register

Re: Finally, a draft of the Asciidoctor extension API has landed!

Posted by mojavelinux on Aug 23, 2013; 10:15am
URL: https://discuss.asciidoctor.org/Finally-a-draft-of-the-Asciidoctor-extension-API-has-landed-tp455p506.html

I'm happy to announce that the pull requests for the extensions have been merged into master! And that means the ball is rolling on the 0.1.4 release. I'm planning on pushing a release candidate on Fri or Sat and hopefully a release at the beginning of the week.

As it turned out, I had to do a pretty massive overhaul of how Asciidoctor was reading files in order to make the behavior more consistent once extensions were added to the mix. I'll include details in the release notes about what changed, why and what it means.

With the rework of the reader came some changes to the extension API. For instance, the IncludeProcessor used to accept an array of lines and return either the same array or a replacement. While simple and straightforward, it's too primitive to work correctly in AsciiDoc. It lacks any context about what changed in the lines and where the new lines originated for things like error reporting, etc. Thus, now the IncludeProcessor gets a Reader object and when it has new content to add, it needs to call Reader#push_include to push the new data onto the stack with the proper context.

Here's a sample boilerplate text IncludeProcessor as an example:

class BoilerplateTextIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
  def handles? target
    target == 'lorem-ipsum.txt'
  end

  def process reader, target, attributes
    lines = ["Lorem ipsum dolor sit amet...\n"]
    reader.push_include lines, '<extension>', target, 1, attributes
  end
end

I plan to include plenty of other examples in the release notes, blog entry and/or docs.

I'll reiterate that these APIs are highly experimental. You should consider working with them if you want to help shape and refine them. My hope is that we can say that they are reasonably stable for the 1.5.0 release (when we finally get out from under to 1.0.0 glass ceiling).

-Dan