asciidoctor / asciidoctor-reveal.js

:crystal_ball: A reveal.js converter for Asciidoctor and Asciidoctor.js. Write your slides in AsciiDoc!
http://asciidoctor.org
Other
287 stars 189 forks source link

Imagesdir is not prepended to image path on included asciidoc files #534

Open Tabea4 opened 1 week ago

Tabea4 commented 1 week ago

Hi all,

I encountered a strange behavior when trying to include images using the imagesdir attribute. The image directory is not prepended to the image path when the asciidoc file is included via another asciidoc file.

Following minimal example illustrates the issue:

Version:

Asciidoctor reveal.js 5.1.0 using Asciidoctor 2.0.20 [https://asciidoctor.org]
Runtime Environment (ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux-musl]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

Command:

asciidoctor-revealjs -r asciidoctor-diagram ./document-revealjs.adoc -o index.html

Example:

- Content of `document-revealjs.adoc`

= Presentations

ifndef::imagesdir[] :imagesdir: presentation/images endif::[]

image::TestImage1.png[]

include::presentation/subdocument-revealjs.adoc[leveloffset=1]

- Content of `subdocument-revealjs.adoc`

= Subdocument

ifndef::imagesdir[] :imagesdir: images endif::[]

image::TestImage2.png[]



- Result in `index.html`

TestImage1

TestImage2 <-- PATH NOT PROPERLY PREPENDED


Here, the second image path is not resolved properly. It should be `<img src="presentation/images/TestImage2.png" alt="TestImage2">`

I found several workarounds for this issue, which are however not ideal. 

**Workarounds:**

**Workaround 1**

- Adding a frame around the image in `subdocument-revealjs.adoc`
- Issue: A lot of extra work when including images 

ifndef::imagesdir[] :imagesdir: images endif::[]

= Subdocument

[frame="none", grid="none"] |=== a| image::TestImage2.png[] |===

- Result in `index.html`

TestImage1
TestImage2

**Workaround 2**

- Delete title in `subdocument-revealjs.adoc` (Move title to another position also did not fix the issue) 
- Issue: Missing title is not wanted

ifndef::imagesdir[] :imagesdir: images endif::[]

image::TestImage2.png[]

- Result in `index.html`

TestImage1
TestImage2

**Workaround 3**

- Delete `ifndef` in `subdocument-revealjs.adoc` 
- Issue: Image path is not correct for this asciidcoc file

= Subdocument

:imagesdir: presentation/images

image::TestImage2.png[]

- Result in `index.html`

TestImage1
TestImage2


Could anyone explain why the `imagesdir` property cannot be resolved properly in the above example? 
Why can it be resolved properly when using the workarounds?
Is there any way to harmonize this behavior?

Thank you for having a look into this issue.
ggrossetie commented 6 days ago

I cannot reproduce:

$ cat 534.adoc 
ifndef::imagesdir[]
:imagesdir: presentation/images
endif::[]

image::TestImage1.png[]

include::inc.adoc[leveloffset=1]
$ cat inc.adoc 
= Subdocument

ifndef::imagesdir[]
:imagesdir: images
endif::[]

image::TestImage2.png[]
$ asciidoctor-revealjs -v
Asciidoctor reveal.js 5.1.0 using Asciidoctor 2.0.20 [https://asciidoctor.org]
Runtime Environment (ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)
$ asciidoctor-revealjs 534.adoc -s -o -
<div class="reveal">
<div class="slides">
<div class="imageblock">
<img src="presentation/images/TestImage1.png" alt="TestImage1">
</div>
<section id="_subdocument">
<h2>Subdocument</h2>
<div class="slide-content">
<div class="imageblock">
<img src="presentation/images/TestImage2.png" alt="TestImage2">
</div>
</div>
</section>
</div>
</div>

Maybe a compatibility issue with asciidoctor-diagram. Could you please try without using -r asciidoctor-diagram?

Tabea4 commented 6 days ago

Hi @ggrossetie ,

Using it withou the -r asciidoctor-diagram option did not fix the issue.

I realized that I missed the title in my example. I updated the example for the document-reveal.js.

If you add a title, e.g. = Presentations in your 534.adoc file, could you try to reproduce the issue again?

Deleting the title, seems like a similar workaround as I described in the "Workaround 2" option.

Update:

It seems like the position of the title for the entry document (in the example document-reveal.js) seems to play a role:

ifndef::imagesdir[]
:imagesdir: presentation/images
endif::[]

= Presentations

image::TestImage1.png[]

include::presentation/subdocument-revealjs.adoc[leveloffset=1]

=> Everything works properly ✅

= Presentations

ifndef::imagesdir[]
:imagesdir: presentation/images
endif::[]

image::TestImage1.png[]

include::presentation/subdocument-revealjs.adoc[leveloffset=1]

=> TestImage2 path is not resolved properly ❌