Code Monkey home page Code Monkey logo

Comments (2)

stephenramm avatar stephenramm commented on August 20, 2024 1

There is a fix. Instead of returning a new Reader from your preprocessor, return a new PreprocessorReader initialised with your processed raw lines, thus:

class myPreprocessor <Asciidoctor::Extensions::Preprocessor
  def process document, reader
    Asciidoctor::PreprocessorReader.new document, reader.lines.map {|line|
      # do your stuff here..
      line
     }
  end
end

from asciidoctor-extensions-lab.

mojavelinux avatar mojavelinux commented on August 20, 2024

Unfortunately, this is one of the limitations of a preprocessor. A preprocessor does not see the structure of the AsciiDoc document in any way, aside from the preprocessor directives. As far as the preprocessor is concerned, it's just handling lines of text, some of which may contain preprocessor directives.

If you want the preprocessor to know about the attributes defined in the document header, you first need to parse the document up to the end of the document header, push those attributes into the document object, then allow the preprocessor to proceed.

I've done something similar in the AsciiDoc coalescer script. See https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/scripts/asciidoc-coalescer.rb#L46-L53

What we may want to consider is adding an option to the Preprocessor that tells it to parse the document header in order to extract the attributes, then run on the remaining lines of code. That change would need to happen in core.

from asciidoctor-extensions-lab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.