extension preprocessor
Posted by
plane on
Oct 27, 2013; 12:06pm
URL: https://discuss.asciidoctor.org/extension-preprocessor-tp886.html
Hi list,
I'm trying to use the extension preprocessor to transform the lines in an asciidoc file prior to processing. Although I have something working, I find 'include::' macros are not getting processed, and am not sure how to proceed - I'm perhaps not understanding the rendering process correctly.
I'm currently using the 'process' method in a subclass of preprocessor, and changing or inserting lines in the 'lines' array, as appropriate. I then return a new reader with these new lines.
def process reader, lines
return reader if lines.empty?
# change and insert new rows in 'lines'
return Asciidoctor::Reader.new lines
end
This works well with a self-contained asciidoc file, but if the file contains 'include::' macros, these macros are not processed, and their text is simply inserted in the output html without rendering the document to insert. I have tried 'image::' macros, and these are processed and the image added correctly.
Is the preprocessor an appropriate way to do a source-to-source transform? I was hoping to slot my rewrite of the asciidoc document in as a first stage, aiming to return a set of lines in correct asciidoc syntax for later rendering.
The code I'm working on is
here.
thanks for any help,
Peter.