asciidoctor / asciidoctorj-pdf

AsciidoctorJ PDF bundles the Asciidoctor PDF RubyGem (asciidoctor-pdf) so it can be loaded into the JVM using JRuby.
Apache License 2.0
35 stars 17 forks source link

Problems with custom inline macro extension #62

Closed 0xff-lroe closed 3 years ago

0xff-lroe commented 3 years ago

I'm currently working on a custom Java extension that is able to draw a frame around an existing image. For that an inline macro is used to perform the following steps:

The code/idea for how to integrate "new" image blocks when using an inline macro is taken from here and here

Unfortunately the procedure seems to work somehow for the HTML backend (with some warnings) but not for the PDF backend.

I've provided a sample project that only does the inline macro processing and tries to include an image: https://gitlab.com/0xff-lroe/asciidoctor-pdf-issues. The example project uses Maven and the mentioned Asciidoctor Java extension.

The extension provided here does nothing but trying to integrate an image.

When running the build (like here) you can see that when using the HTML backend the processing works but some warnings appear:

[INFO] asciidoctor: INFO: expected substitution value for custom inline macro to
be of type Inline; got String: passthrough:screenshots/redeemer-portal-01-login.png[width=80%,align="center"]

Running the build (like here) using the PDF backend then the processing fails. The message given back by asciidoctor-pdf is:

org.jruby.exceptions.NoMethodError: (NoMethodError) undefined method `include?' for nil:NilClass
Did you mean?  include_class
    at RUBY.encode_quotes(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/sanitizer.rb:41)
    at RUBY.convert_inline_image(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:2502)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:135)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/inline.rb:32)
    at org.asciidoctor.jruby.extension.processorproxies.InlineMacroProcessorProxy.process(org/asciidoctor/jruby/extension/processorproxies/InlineMacroProcessorProxy.java:123)
    at org.jruby.RubyMethod.call(org/jruby/RubyMethod.java:131)
    at RUBY.sub_macros(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/substitutors.rb:333)
    at org.jruby.RubyString.gsub(org/jruby/RubyString.java:3126)
    at RUBY.sub_macros(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/substitutors.rb:309)
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1809)
    at RUBY.sub_macros(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/substitutors.rb:308)
    at uri_3a_classloader_3a_.gems.asciidoctor_minus_2_dot_0_dot_15.lib.asciidoctor.substitutors.apply_subs(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/substitutors.rb:102)
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1809)
    at RUBY.apply_subs(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/substitutors.rb:91)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/block.rb:113)
    at RUBY.convert_paragraph(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:708)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:135)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:75)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2577)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at RUBY.traverse(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:152)
    at RUBY.convert_section(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:584)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:135)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:75)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2577)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at RUBY.traverse(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:152)
    at RUBY.convert_section(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:584)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:135)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:75)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2577)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/abstract_block.rb:84)
    at RUBY.content(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/document.rb:1013)
    at RUBY.traverse(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:152)
    at RUBY.convert_document(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:261)
    at RUBY.indent_section(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:594)
    at RUBY.convert_document(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:208)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-pdf-1.6.0/lib/asciidoctor/pdf/converter.rb:135)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/document.rb:944)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:117)
    at RUBY.convert_file(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:189)
    at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1158)
    at RUBY.convert_file(uri:classloader:/gems/asciidoctor-2.0.15/lib/asciidoctor/convert.rb:189)

Using asciidoctor-pdf 1.5.4 or 1.6.0 makes no difference.

Do you have any hints for me how to overcome this issue? Or maybe what's the correct way of including images out of inline macros?

Thanks in advance.

robertpanzer commented 3 years ago

Trying to access your project I get a 404. Is your repository private?

0xff-lroe commented 3 years ago

Yes, it was private. Sorry for that. Should work now...

robertpanzer commented 3 years ago

The conversion works for me after adding the "alt" attribute:

passthrough:screenshots/redeemer-portal-01-login.png[width=80%,align="center", alt="alt"]

The HTML backend doesn't seem to fail on that because it uses '' as a default.

@mojavelinux Since asciidoctor-pdf 1.6.0 relies on asciidoctor >= 2.0.0 I guess it could also use node.alt instead of node.attr 'alt' here? https://github.com/asciidoctor/asciidoctor-pdf/blob/1ab33379a06161f330f8869cd5bef4310d6f43cb/lib/asciidoctor/pdf/converter.rb#L2502 Then it should also fall back to an empty alt attribute for the image.

0xff-lroe commented 3 years ago

Works like a charm. Thanks!