Nested blocks in blockprocessor extension

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

Nested blocks in blockprocessor extension

nurkkala
Within a block processor, is it possible to create a block from scratch? For example, while processing an open block, could I arrange to output another block that either wraps the open block (becomes its parent), or one that precedes it in the output (becomes its previous sibling)?
Reply | Threaded
Open this post in threaded view
|

Re: Nested blocks in blockprocessor extension

mojavelinux
Administrator
That's exactly what block processors are designed to do. They can insert any set of nodes into to the AST (the document model).

Here's an example:

wrapper = create_open_block parent, [], {}
wrapper << (create_open_block wrapper, reader.lines, attrs)
wrapper

(You have to decide where you want the attributes to go, but that's the general idea

Here's the APIs to be looking at:


Note that `create_open_block` is just a shorthand for `create_block parent, :open, ...`

-Dan

On Fri, Jan 29, 2016 at 9:07 AM, nurkkala [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Within a block processor, is it possible to create a block from scratch? For example, while processing an open block, could I arrange to output another block that either wraps the open block (becomes its parent), or one that precedes it in the output (becomes its previous sibling)?


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



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Nested blocks in blockprocessor extension

nurkkala
Got it. I had missed the use of the append operation to insert the "sub-block" in the newly built one. Actually occurred to me after I went to bed and stopped thinking about the problem. :-)