asciidoctorj and document attributes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

asciidoctorj and document attributes

rockyallen
In a treeprocessor, I want to get the current value of att from:

= Title
:att: 1
= block1
text
:att: 2
=block2
text

From experimenting, I *think*
block.getDocument.getAttributes() returns environment attributes + header attributes as they were defined at the start of processing;
block.getAttributes() returns things like role and style, ie just the attributes that are specific to that block.
Is it possible to get the value of a document attribute as it is immediately prior to the block?

Using 1.6.0-alpha.5 via asciidoctor-ant.
Reply | Threaded
Open this post in threaded view
|

Re: asciidoctorj and document attributes

mojavelinux
Administrator
rockyallen,

This has come up often and, unfortunately, a limitation of the Asciidoctor processor at the moment. The in-flow document attributes are not available to the AST. They get "played" once when the document is parsed and once again when the document is converted. Depending on where your code runs in processing lifecycle, you may see different values.

What needs to happen is that core needs to designate a node for an attribute entry so they live in the tree. Well, technically, they do live in the tree, but they are in a private area.

Without changing core too much, one possible idea is to make the document attribute accessible via the block (since it's already stored on the block). That might look something like block.getDocumentAttributes(). (These are not the same as block.getDocument().getAttributes()).

I think the next step is to open an issue in asciidoctor/asciidoctor to discuss whether in-flow document attributes should be in the AST and, if so, what are they called, where do they go, and how do we access them.

Cheers,

-Dan

On Sun, Oct 8, 2017 at 3:56 AM rockyallen [via Asciidoctor :: Discussion] <[hidden email]> wrote:
In a treeprocessor, I want to get the current value of att from:

= Title
:att: 1
= block1
text
:att: 2
=block2
text

From experimenting, I *think*
block.getDocument.getAttributes() returns environment attributes + header attributes as they were defined at the start of processing;
block.getAttributes() returns things like role and style, ie just the attributes that are specific to that block.
Is it possible to get the value of a document attribute as it is immediately prior to the block?

Using 1.6.0-alpha.5 via asciidoctor-ant.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/asciidoctorj-and-document-attributes-tp5960.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