asciidoctorj and document attributes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 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
Reply | Threaded
Open this post in threaded view
|

Re: asciidoctorj and document attributes

Daniel K
This post was updated on .
Hi all,
does somebody know if there is already solution for this issue?

I am facing the same problem:

====== Title
[#myid]
:status: new
:otherattr:
--
Bla Bla Bla
--

I need to access the attributes :status:, :otherattr: within a TreeProcessor.

Is there maybe a workaround in asciidoctorj 1.6.x? E.g. using Ruby directly?

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

Re: asciidoctorj and document attributes

David Jencks
You have to:

— traverse the entire tree in order
— replay the attributes, and when you’re done reset them.

If you can understand javascript, you can find an example in David Jencks / asciidoctor-mathjax.js
I assume the necessary methods are exposed in AsciidoctorJ, but I don’t know, and there seem to be some limitations there, so it might not be possible.

David Jencks

On May 12, 2020, at 8:19 AM, Daniel K [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Hi all,
does somebody know if there is already solution for this issue?

I am facing the same problem:

====== Title
[#myid]
:status: new
:otherattr:
--
Bla Bla Bla
--

I need to access the attributes :status:, :otherattr: within a TreeProcessor.

Is there maybe a workaround in asciidoctorj 1.6.x?

Thanks!


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/asciidoctorj-and-document-attributes-tp5960p7988.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: asciidoctorj and document attributes

Daniel K
I fear that playback_attributes is not exposed on asciidoctorj - at least I couldn't find it.
Is there any other workaround? Is it somehow possible to expose it?

It also seems that the issue has been open for a very long time: https://github.com/asciidoctor/asciidoctorj/issues/139

Thanks!
Regards,
Daniel