order of extension processing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

order of extension processing

ttmetro
I've created 2 extension, a BlockProcessor and an InlineMacroProcessor.

Apparently they are executed in different phases: first the BlockProcessor is called to handle all the blocks, later the InlineMacroProcessor.

I need their attributes in the sequence they appear in the document. Is there a way to do this?

Motivation: the block and macro process Python code, that is written to a file, evaluated, and in a later pass inserted into the document. E.g. the block might set up a computation, the macro display the results inline.

Thanks!
Bernhard
Reply | Threaded
Open this post in threaded view
|

Re: order of extension processing

mojavelinux
Administrator
Bernhard,

You have correctly derived that a block processor an inline macro processor operate in different phases. This stems from the fact that Asciidoctor only parses down to the block level during the parse phase. All inline parsing is deferred until the convert phase. This will eventually be fixed, as tracked by https://github.com/asciidoctor/asciidoctor/issues/61.

The best thing I can advise is to capture the document attributes you want at the time the block is processed and store them somewhere as a stack, such as on the block or in the document.catalog. Then, consult that stack when processing the inline macro. In other words, you need to do some state management yourself.

I hope that helps! Let me know if you need more info.

Cheers,

-Dan

On Tue, Nov 6, 2018 at 11:53 AM ttmetro [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I've created 2 extension, a BlockProcessor and an InlineMacroProcessor.

Apparently they are executed in different phases: first the BlockProcessor is called to handle all the blocks, later the InlineMacroProcessor.

I need their attributes in the sequence they appear in the document. Is there a way to do this?

Motivation: the block and macro process Python code, that is written to a file, evaluated, and in a later pass inserted into the document. E.g. the block might set up a computation, the macro display the results inline.

Thanks!
Bernhard


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/order-of-extension-processing-tp6581.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: order of extension processing

ttmetro
Hi Dan,

I ended up writing a preprocessor but kept the syntax compatible with "normal" adoc. So if eventually the parser is modified, my sources should be possible to process with an extension.

Thanks!
Bernhard