asciidoc asciidoctor include adocs and their images
Asked Answered
R

2

5

I am building my asciidoc template to manage my development documentations. Therefor I want to be able to link existing ascii documents into a main / or a new document inclusive images and other resources. To link documents I use the include keyword that works to reference documents into a new one.

Problem

My Problem is, that the images of the included / referenced document are not shown. I am aware that the path resolution for the image starts from the main document and does not match with the path from the included / referenced document images. The image paths in the included document are correct. The images are shown when generating only the included document. Does anyone have a good solution to solve that?

Example of the not working document include with images

1. Directory structure of the documents.

main.adoc includes Risikoanalyse_v2.adoc that contains the images

  • ./main.adoc
  • ./Risikoanalysen/Risikoanalyse_v2.adoc
  • ./Risikoanalysen/Risikodiagramm_1_v2.png
  • ./Risikoanalysen/Risikodiagramm_2_v2.png

2. Content of the main.adoc document

== Content 1

ratatata

include::./Risikoanalysen/Risikoanalyse_v2.adoc[]

3. Content of the Risikoanalyse_v2.adoc

= Risikoanalyse 
Inhaltsverzeichnis
:doctype: book
:toc: left
:toclevels: 4
:sectnums:

:version: Version 2.0, 03.03.2019
{version}

<<<
== Risiken
bachelor party

image::Risikodiagramm_1_v2.png[Risikodiagramm,300,align="center"]       // image that is not resolved

<<<
== preventive Gegenmassnahmen
rooftop party

image::Risikodiagramm_2_v2.png[Risikodiagramm,300,align="center"]       // image that is not resolved

4. Command to generate the documents

  • asciidoctor main.doc*
  • asciidoctor-pdf main.doc
Rearward answered 10/3, 2019 at 9:35 Comment(0)
N
5

I'm not sure if you tried that.

Add all images in a directory ./images. This is the default directory where asciidoctor get's the image from.

Your links stay the same:

image::Risikodiagramm_2_v2.png[Risikodiagramm,300,align="center"]

You can configure this path:

:imagesdir: myImages

See https://asciidoctor.org/docs/user-manual/#setting-the-location-of-images

Naked answered 15/3, 2019 at 14:48 Comment(0)
L
2

This code snippet works for my use case which is: render images in partial documents for e.g. when you just want to read a single module doc + render images in the main document which is used to provide consolidated documentation with all partial documents in one place.

Solution is prepared with one common images directory for all the files.

  1. Main document main.adoc to include other partial documentation:
    = Main document
    :imagesdir: ./doc/_images
    
    include::./modules/README.adoc[leveloffset=2]
    
  2. Partial documentation ./modules/README.adoc, used separately and as a part of a big main.adoc document:
    = Modules documentation
    ifndef::imagesdir[:imagesdir: ../doc/_images]
    
    image::image_file_name.png[]
    

Credit goes to https://github.com/asciidoctor/asciidoctor-pdf/issues/93#issuecomment-222029230.

Langton answered 31/3, 2022 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.