asciidoctor gradle inline extension: Correct format for image createBlock?

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

asciidoctor gradle inline extension: Correct format for image createBlock?

Arnold Iterate

I'd like to implement a custom block process that reads lines from a 'listing' block to create an 'image' block.
I waded through the asciidoctor-diagram code and the asciidoctorj extension test code to try to figure out the correct arguments to the 'createBlock' call to create an image but haven't gotten there yet.  I can't find any examples of
createBlock for an imageBlock.
My actual use case is to use GroovyFX to build a JavaFX scene then write the scene to a PNG.

Below is the essence of what I have in my build.gradle file to define the extension.
The extension code is invoked but blows up on the createBlock.
I think the 'content' of an image block should be empty.
What does asciidoctor expect for the image block?
How do I pass the 'src', 'alt', 'width', and 'height'?
How do I get hold of the value of the 'imagesdir' or 'outputdir' property to control where I write my image?
Stack trace below.

      block(name: "custom", contexts: [":listing"]) {parent, reader, attributes ->
          def src = read.lines();
          //<Custom code which uses 'src' to write out a PNG>
          createBlock(parent, "image", [], attributes, [:])
      }

Thanks for any assistance.
I love the whole asciidoctor ecosystem.


Caused by: org.jruby.exceptions.RaiseException: (TypeError) asciidoctor: FAILED: /home/dayjob/fcm/armcm/Publish/src/docs/asciidoc/test3.adoc: Failed to parse source, can't convert nil into String
        at RUBY.load(/home/dayjob/fcm/armcm/Publish/build/vendor/gems/asciidoctor-1.5.2/lib/asciidoctor.rb:1362)
        at RUBY.convert(/home/dayjob/fcm/armcm/Publish/build/vendor/gems/asciidoctor-1.5.2/lib/asciidoctor.rb:1458)
        at RUBY.convert_file(/home/dayjob/fcm/armcm/Publish/build/vendor/gems/asciidoctor-1.5.2/lib/asciidoctor.rb:1562)
        at RUBY.convertFile(<script>:68)
        at org.jruby.gen.InterfaceImpl310998397.convertFile(org/jruby/gen/InterfaceImpl310998397.gen:13)
        at org.asciidoctor.gradle.AsciidoctorProxyImpl.renderFile(AsciidoctorProxyImpl.groovy:26)
        at org.asciidoctor.gradle.AsciidoctorTask.processSingleFile(AsciidoctorTask.groovy:672)
        at org.asciidoctor.gradle.AsciidoctorTask$_processDocumentsAndResources_closure7.doCall(AsciidoctorTask.groovy:652)
        at org.asciidoctor.gradle.AsciidoctorTask.processDocumentsAndResources(AsciidoctorTask.groovy:647)
        at org.asciidoctor.gradle.AsciidoctorTask.processAsciidocSources(AsciidoctorTask.groovy:592)
Reply | Threaded
Open this post in threaded view
|

Re: asciidoctor gradle inline extension: Correct format for image createBlock?

Arnold Iterate
Partially answering my own question...

Found the attributes being referenced by asciidoctor in the asciidoctor source code 'converter/html5.rb'.

The following is sufficient to cause the img tag to show up in the rendered doc.
Width and height are optional.

block(name: "custom", contexts: [":listing"]) {parent, reader, attributes ->
          def src = reader.lines();
          // <Custom code here...>
          attributes.put('target', 'target.png')
          attributes.put('alt', 'alt')
          attributes.put('width', 40)
          attributes.put('height', 50)
          createBlock(parent, "image", [], attributes, [:])
      }