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

Extend Preprocessors to return Readers #1081

Merged
merged 4 commits into from
Jul 23, 2022

Conversation

robertpanzer
Copy link
Member

Kind of change

  • Bug fix
  • New non-breaking feature
  • New breaking feature
  • Documentation update
  • Build improvement

Description

What is the goal of this pull request?

The Asciidoctor API currently allows a preprocessor to return a reader.
The AsciidoctorJ API does not allow this, making certain preprocessors awkward or even impossible.
This PR wants to align the AsciidoctorJ API with the API of Asciidoctor.

How does it achieve that?

I added method to the Processor base class to create new readers.
The Preprocessor API is extended to return a Reader instead of void.
If a preprocessor returns null, or the original reader, the processor proxy returns nil to Asciidoctor.
Otherwise the new Reader is returned.

As a PoC I've implemented the FrontMatterPreprocessor (which does not create a new reader) and the HardBreaksPreprocessor (which does).

Are there any alternative ways to implement this?

I was first considering to allow creation of new Readers directly, but of course that doesn't work in an implementation neutral way, also Reader exposes a complex API and internal state that is not easy to reimplement correctly from scratch for a simple extension.

Are there any implications of this pull request? Anything a user must know?

!!!It's a breaking change! Even recompiling will not work, so this would pull the trigger for a 3.0!!!

Issue

If this PR fixes an open issue, please add a line of the form:

Fixes #Issue

Release notes

Please add a corresponding entry to the file CHANGELOG.adoc

Add a Processor method to create a new Reader from a list of source lines.
Update example preprocessor to use newReader().
@robertpanzer robertpanzer force-pushed the frontmatter-preprocessor branch from 5363408 to f9abf6c Compare July 23, 2022 09:34
@robertpanzer
Copy link
Member Author

Updated the PR with an extension migration guide which documents the necessary changes for existing preprocessors, and updated the docs to let the sample Preprocessor use Processor.newReader() instead of Reader.restoreLines().

@robertpanzer robertpanzer merged commit c68b7a1 into asciidoctor:main Jul 23, 2022
@robertpanzer robertpanzer deleted the frontmatter-preprocessor branch May 29, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants