How to exploit ContentPart attributes (RubyHash) from Java

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

How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
Hello,

I am writing a simple tool in Java to parse the content of simple AsciiDoc files using AsciidoctorJ 1.5.6.

The documents define some header attributes which may be overriden later in the document.

In the following code, I initialize an attribute map from the document header. Then, I want to update it with attributes from the current ContentPart.


        StructuredDocument document = asciidoctor.readDocumentStructure(file, Collections.emptyMap());

        DocumentHeader header = document.getHeader();

        // Initialize attributes with header content
        Map<String, Object> attributes = new HashMap<>(header.getAttributes());

        for (ContentPart part : document.getParts()) {
           
            // Then overwrite with section attributes
            attributes.putAll(part.getAttributes());

            String id = (String) attributes.get("id");
            String title = (String) attributes.get("title");
           ....
        }

Sadly, this does not work. The document header attributes are exposed as a Java HashMap but content part attributes are exposed through a RubyHash object with a surprising structure (at least to me).

Can someone help me convert the RubyHash into a HashMap ?

Kind regards,

Michaël
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

mojavelinux
Administrator
Michaël,

You should no longer being using the ContentPart API. That API has been deprecated for some time and has been removed from AsciidoctorJ 1.6.0 and 2.0.0. But I have good news for you! That API has been replaced with a much better API that aligns closely with Asciidoctor Ruby and is far more capable. Here's a link to the API docs for that API:

https://static.javadoc.io/org.asciidoctor/asciidoctorj/2.0.0-RC.1/org/asciidoctor/ast/package-summary.html

The newer API converts all types as you would expect them to be converted.

Cheers,

-Dan

On Wed, Apr 3, 2019 at 7:03 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I am writing a simple tool in Java to parse the content of simple AsciiDoc files using AsciidoctorJ 1.5.6.

The documents define some header attributes which may be overriden later in the document.

In the following code, I initialize an attribute map from the document header. Then, I want to update it with attributes from the current ContentPart.


        StructuredDocument document = asciidoctor.readDocumentStructure(file, Collections.emptyMap());

        DocumentHeader header = document.getHeader();

        // Initialize attributes with header content
        Map<String, Object> attributes = new HashMap<>(header.getAttributes());

        for (ContentPart part : document.getParts()) {
           
            // Then overwrite with section attributes
            attributes.putAll(part.getAttributes());

            String id = (String) attributes.get("id");
            String title = (String) attributes.get("title");
           ....
        }

Sadly, this does not work. The document header attributes are exposed as a Java HashMap but content part attributes are exposed through a RubyHash object with a surprising structure (at least to me).

Can someone help me convert the RubyHash into a HashMap ?

Kind regards,

Michaël



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827.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: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
Dan,

I have switched to AsciidoctorJ 1.6.0 to use the new API.

Thank you for your input.

Michaël

Le mer. 3 avr. 2019 à 20:51, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

You should no longer being using the ContentPart API. That API has been deprecated for some time and has been removed from AsciidoctorJ 1.6.0 and 2.0.0. But I have good news for you! That API has been replaced with a much better API that aligns closely with Asciidoctor Ruby and is far more capable. Here's a link to the API docs for that API:

https://static.javadoc.io/org.asciidoctor/asciidoctorj/2.0.0-RC.1/org/asciidoctor/ast/package-summary.html

The newer API converts all types as you would expect them to be converted.

Cheers,

-Dan

On Wed, Apr 3, 2019 at 7:03 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I am writing a simple tool in Java to parse the content of simple AsciiDoc files using AsciidoctorJ 1.5.6.

The documents define some header attributes which may be overriden later in the document.

In the following code, I initialize an attribute map from the document header. Then, I want to update it with attributes from the current ContentPart.


        StructuredDocument document = asciidoctor.readDocumentStructure(file, Collections.emptyMap());

        DocumentHeader header = document.getHeader();

        // Initialize attributes with header content
        Map<String, Object> attributes = new HashMap<>(header.getAttributes());

        for (ContentPart part : document.getParts()) {
           
            // Then overwrite with section attributes
            attributes.putAll(part.getAttributes());

            String id = (String) attributes.get("id");
            String title = (String) attributes.get("title");
           ....
        }

Sadly, this does not work. The document header attributes are exposed as a Java HashMap but content part attributes are exposed through a RubyHash object with a surprising structure (at least to me).

Can someone help me convert the RubyHash into a HashMap ?

Kind regards,

Michaël



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6828.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
This post was updated on .
Dan,

On a simple example, I think I don't understand the new API:

:subsystem: Test
= Sample Document

:subsystem: NewValue
== Sample Section
:subsystem: NewValue2

        Document document = asciidoctor.loadFile(file, Collections.emptyMap());

        // Initialize attributes with header content
        Map<String, Object> attributes = new HashMap<>(document.getAttributes());

        System.out.println(document.getAttributes());
        System.out.println(document.getOptions());
        System.out.println(document.getSubstitutions());


        for (StructuralNode node : document.getBlocks()) {
            
            // Then overwrite with section attributes
            Map<String, Object> nodeAttributes = node.getAttributes();
            attributes.putAll(nodeAttributes);

            System.out.println(node.getAttributes());
            System.out.println(node.getBlocks());

            for (StructuralNode block : node.getBlocks()) {
                System.out.println("SUBNODE");
                System.out.println(block.getAttributes());
                System.out.println(block.getBlocks());
            }
       }

document.getAttributes returns expected values. But,  node.getAttributes() only returns empty maps. I have checked other available methods to see if additional ast navigation would help but, so far,  I fail to see how I can get new attributes values from the exposed AST.

Cheers,

Michaël


Michaël Melchiore wrote
Dan,

I have switched to AsciidoctorJ 1.6.0 to use the new API.

Thank you for your input.

Michaël

Le mer. 3 avr. 2019 à 20:51, mojavelinux [via Asciidoctor :: Discussion] <
[hidden email]> a écrit :

> Michaël,
>
> You should no longer being using the ContentPart API. That API has been
> deprecated for some time and has been removed from AsciidoctorJ 1.6.0 and
> 2.0.0. But I have good news for you! That API has been replaced with a much
> better API that aligns closely with Asciidoctor Ruby and is far more
> capable. Here's a link to the API docs for that API:
>
>
> https://static.javadoc.io/org.asciidoctor/asciidoctorj/2.0.0-RC.1/org/asciidoctor/ast/package-summary.html
>
> https://static.javadoc.io/org.asciidoctor/asciidoctorj/2.0.0-RC.1/org/asciidoctor/ast/Document.html
>
> The newer API converts all types as you would expect them to be converted.
>
> Cheers,
>
> -Dan
>
> On Wed, Apr 3, 2019 at 7:03 AM Michaël Melchiore [via Asciidoctor ::
> Discussion] <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=6828&i=0>> wrote:
>
>> Hello,
>>
>> I am writing a simple tool in Java to parse the content of simple
>> AsciiDoc files using AsciidoctorJ 1.5.6.
>>
>> The documents define some header attributes which may be overriden later
>> in the document.
>>
>> In the following code, I initialize an attribute map from the document
>> header. Then, I want to update it with attributes from the current
>> ContentPart.
>>
>>
>>         StructuredDocument document =
>> asciidoctor.readDocumentStructure(file, Collections.emptyMap());
>>
>>         DocumentHeader header = document.getHeader();
>>
>>         // Initialize attributes with header content
>>         Map<String, Object> attributes = new
>> HashMap<>(header.getAttributes());
>>
>>         for (ContentPart part : document.getParts()) {
>>
>>             // Then overwrite with section attributes
>>             attributes.putAll(part.getAttributes());
>>
>>             String id = (String) attributes.get("id");
>>             String title = (String) attributes.get("title");
>>            ....
>>         }
>>
>> Sadly, this does not work. The document header attributes are exposed as
>> a Java HashMap but content part attributes are exposed through a RubyHash
>> object with a surprising structure (at least to me).
>>
>> Can someone help me convert the RubyHash into a HashMap ?
>>
>> Kind regards,
>>
>> Michaël
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827.html
>> To start a new topic under Asciidoctor :: Discussion, email [hidden
>> email] <http:///user/SendEmail.jtp?type=node&node=6828&i=1>
>> To unsubscribe from Asciidoctor :: Discussion, click here.
>> NAML
>> <http://discuss.asciidoctor.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
> --
> Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6828.html
> To unsubscribe from How to exploit ContentPart attributes (RubyHash) from
> Java, click here
> <http://discuss.asciidoctor.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6827&code=cm9oZWwwMUBnbWFpbC5jb218NjgyN3wxMTk0MTEyMzQ0>
> .
> NAML
> <http://discuss.asciidoctor.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have let you to believe I want to detect attribute value changes in arbitray places of the document.
This is not the case, my need is much simpler and I control the layout of the document. For instance, I could enforce one top level Asciidoc document referencing sub documents each containing a single requirement. This would work since I can already define and access document attributes.

Still, I find the current API surprising. Clarifications are welcomed :)
 
Michaël
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

mojavelinux
Administrator
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
Dear Dan,

Thanks for your inputs.
How can I reference the block attributes ?

For example,

[subsystem=NewValue]
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


Kind regards,

Michaël


Le jeu. 4 avr. 2019 à 23:25, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6835.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
Currently, I use this hack

:subsystem: NewValue
[subsystem='{subsystem}']
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


If you know of a better way, I am interested.

Kind regards,

Michaël




Le ven. 5 avr. 2019 à 10:47, Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Dear Dan,

Thanks for your inputs.
How can I reference the block attributes ?

For example,

[subsystem=NewValue]
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


Kind regards,

Michaël


Le jeu. 4 avr. 2019 à 23:25, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6835.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6836.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: How to exploit ContentPart attributes (RubyHash) from Java

mojavelinux
Administrator
In reply to this post by Michaël Melchiore
Michaël,

You can't. These are two different things. Block attributes are for labeling. Document attributes are for content. (Though you can use a document attribute in the value of a block attribute).

Cheers,

-Dan

On Fri, Apr 5, 2019 at 2:47 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Dear Dan,

Thanks for your inputs.
How can I reference the block attributes ?

For example,

[subsystem=NewValue]
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


Kind regards,

Michaël


Le jeu. 4 avr. 2019 à 23:25, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6835.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6836.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: How to exploit ContentPart attributes (RubyHash) from Java

mojavelinux
Administrator
In reply to this post by Michaël Melchiore
That's not a hack. That's the way it's designed. But you don't need to use single quotes for the block attribute because attributes are replaced by default. (You can just use double quotes or no quotes).

Cheers,

-Dan

On Fri, Apr 5, 2019 at 2:52 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Currently, I use this hack

:subsystem: NewValue
[subsystem='{subsystem}']
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


If you know of a better way, I am interested.

Kind regards,

Michaël




Le ven. 5 avr. 2019 à 10:47, Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Dear Dan,

Thanks for your inputs.
How can I reference the block attributes ?

For example,

[subsystem=NewValue]
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


Kind regards,

Michaël


Le jeu. 4 avr. 2019 à 23:25, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6835.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6836.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6837.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: How to exploit ContentPart attributes (RubyHash) from Java

Michaël Melchiore
Ok, I understand now.

Thank you for your time.

Michaël

Le ven. 5 avr. 2019 à 10:55, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
That's not a hack. That's the way it's designed. But you don't need to use single quotes for the block attribute because attributes are replaced by default. (You can just use double quotes or no quotes).

Cheers,

-Dan

On Fri, Apr 5, 2019 at 2:52 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Currently, I use this hack

:subsystem: NewValue
[subsystem='{subsystem}']
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


If you know of a better way, I am interested.

Kind regards,

Michaël




Le ven. 5 avr. 2019 à 10:47, Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Dear Dan,

Thanks for your inputs.
How can I reference the block attributes ?

For example,

[subsystem=NewValue]
== {subsystem} requirements
This section describes the requirements allocated to {subsystem}


Kind regards,

Michaël


Le jeu. 4 avr. 2019 à 23:25, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> a écrit :
Michaël,

I think what you're looking for are block attributes instead of document attributes. These are specified differently.

[subsystem=NewValue]
== Sample Section

Now, when you look for the attributes on a node, you will find "subsystem" among them.

Document attributes that are changed mid-document are not available to the AST (without doing some magic incantations). That's because document attributes are not part of the AST beyond the document header. This is explained here: https://github.com/asciidoctor/asciidoctor/issues/1485#issuecomment-142184143

Cheers,

-Dan

On Thu, Apr 4, 2019 at 10:49 AM Michaël Melchiore [via Asciidoctor :: Discussion] <[hidden email]> wrote:
To give a bit of context, I intended to use attributes to tag special values for easy programmatic access when parsing the document.

For example, I was thinking on writing software requirement documents with AsciiDoc and use AsciidoctorJ to implement some tooling.

Each top level section of the document would be dedicated to a software requirement. I thought section attributes would be useful to capture some metadata about each requirement (allocated subsystem, target version...).
I could use the attribute in two interesting ways:

* reference in the requirement text to avoid duplicating information
* from the Java API to efficiently access the metadata value without complex and fragile requirement text parsing logic

So my use case is that one section has a set of fixed attributes each with a single value. My previous example could have lead you to believe I want to detect attribute value changes in arbitray places of the document. This is not the case, my need is much simpler and I control the layout of the document.

Michaël


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6832.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6835.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6836.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6837.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



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6839.html
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java, click here.
NAML