Images cannot be resolved when converting to non-PDF formats

When using an exporter other than PDF, such as EPUB or HTML, images cannot be resolved. There are different reasons for why they cannot be resolved, albeit with a common cause.

When converting to HTML, images cannot be resolved by the browser because the image tag points to an absolute path on the filesystem. Instead, the path to the image should be relative, and it should resolve to a resource in the published site.

When converting the EPUB, images cannot be resolved because Asciidoctor EPUB3 cannot resolve images outside of the docdir. What ends up happening is that the absolute path gets corrupted, so the image is not bundled, and the path to that image in the manifest invalid anyway.

Both problems are rooted in the fact that Assembler sets the imagesdir attribute to an absolute (filesystem) path. Assembler should instead set imagesdir to a relative path from the location of the source file to the Assembler build directory (e.g, ../../..). (We could consider rewriting the image target so the imagesdir attribute is not needed at all, but this would invalidate the workaround for EPUB described below).

Furthermore, the docdir attribute should be set to an absolute path (or a relative path that includes the Assembler build directory). If the attribute were to be set to a relative path from the Assembler build directory (like the docfile attribute is currently), when docdir is combined with imagesdir, it would result in a non-existent directory. If the docdir attribute is set to an absolute path, so should the docfile attribute.

See https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/#intrinsic-attributes

These changes still won't fix EPUB conversion. That's because, as stated above, Asciidoctor EPUB3 cannot resolve images outside of docdir. Since the exporter is passing the AsciiDoc source in as a string, the docdir is really just made up. So the EPUB exporter can set the docdir attribute to the build directory and clear the imagesdir attribute. We may even want to think about whether Assembler itself should just use those values by default.

Edited by Dan Allen