Login  Register

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

Posted by mojavelinux on Apr 03, 2019; 6:51pm
URL: https://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6828.html

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