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

Using the Preprocessor ignores ifdef directives #123

Open
ungive opened this issue Jan 30, 2021 · 1 comment
Open

Using the Preprocessor ignores ifdef directives #123

ungive opened this issue Jan 30, 2021 · 1 comment

Comments

@ungive
Copy link

ungive commented Jan 30, 2021

Extensions::Preprocessor breaks ifdef directives. This was reported previously in #62.

I made these changes: ungive@b0a42dc

I ran the following command with corresponding input and part of the output:

asciidoctor -r ./lib/tex-preprocessor.rb lib/tex-preprocessor/sample.adoc
:first:

ifndef::first[]
Hidden
endif::first[]

:first!:

ifndef::first[]
Visible
endif::first[]
<div class="paragraph">
<p>Hidden</p>
</div>
<div class="paragraph">
<p>Visible</p>
</div>

The gist of the extension code is this:

Extensions.register do
  preprocessor TeXPreprocessor
end

class TeXPreprocessor < Extensions::Preprocessor
  def process document, reader
    return reader if reader.eof?
    reader.unshift_lines reader.read_lines  # this is the culprit
    reader
  end
end

Adding reader.unshift_lines reader.read_lines breaks the conditional ifdef directives.

@mojavelinux
Copy link
Member

This is a known limitation of a preprocessor and why I strongly discourage using it to manipulate any lines. Instead it should be treated only as an event. Manipulating lines can be done, but it must be done extremely carefully to avoid exactly these types of side effects. So it's a "caveat emptor" kind of extension point.

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

No branches or pull requests

2 participants