include and imagesdir in different folders

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

include and imagesdir in different folders

yo
This post was updated on .
Hi,
I need the {user-home} environment variable in my asciidoc scripts. It works perfectly with the asciidoctor plugin in atom but doesn't render with Brave (close to Chromium). Tried to add environment variable in the asciidoctor.js plugin but unsuccessful.
Any idea?
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

mojavelinux
Administrator
It's very unlikely this is going to work automatically since the browser plugin is restricted in what information can access from the local system.

I'm confident you can set the attribute manually in the options page of the extension (https://github.com/asciidoctor/asciidoctor-browser-extension#options). However, you will need to use a different attribute name, like "home".

home=/home/username

That's because the user-home attribute is hard-coded as ".". If you think it should be possible to override this attribute from the options page, please comment on the issue in the issue tracker.

Best Regards,

-Dan

On Sun, Aug 9, 2020 at 2:39 AM yo [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi,
I need the {user-home} environment variable in my asciidoc scripts. It works perfectly with the asciidoctor plugin in atom but doesn't render with Brave (close to Chromium). Tried to add environment variable in the asciidoctor.js plugin but unsuccessful.
Any idea?


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chrome-Asciidoctor-js-plugin-environment-variables-tp8154.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux
yo
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

yo
Hi Dan,
You are right. home=/home/username works.

I am here because I use :imagesdir: to display images. However, my code is shared on git and I want everyone to have it functional at the first time. The folder is under $HOME/folder.

First I was using :imagesdir: as :imagesdir: ../../../src/img. But as I use some include, it can not resolve them when they are not in the same folder. Were you aware of this issue?

Then I decided to use {user-home} that solved this particular issue but then facing the plugins environment variables. Indeed, I can not override it. But I would like the same script to be functional for all the programs that are going to interpret it such as atom, asciidoctor, etc.

These lines seems to work in atom and brave at the same time :
:home: {user-home}
:imagesdir: {home}/path/to/img/


The brave asciidoctor plugin seems to not care at the :home: {user-home} declaration.

Do you have a better solution for me ?

The browser app should have in its parameters the $HOME environment variable ? I am not sure to understand the user-home attribute is hard-coded as ".", it makes reference to $HOME, no ? There is no asciidoctor attribute making reference to $HOME ?
Thanks for your time.
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

mojavelinux
Administrator


The browser app should have in its parameters the $HOME environment variable ? I am not sure to understand the user-home attribute is hard-coded as ".", it makes reference to $HOME, no ? There is no asciidoctor attribute making reference to $HOME ?
Thanks for your time.

That's a question for the browser extension project. I recommend reposting this comment on the issue you filed. I'm not the author of the extension.

As for whether you should use {user-home} to define the location of images, that's up to you. If it works for you, I'm not going to tell you not to do it. However, it's probably not what I would do. I would keep the images relative to the document so that the content is portable.

Best Regards,

-Dan

--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux
yo
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

yo
Yes, I would prefer to keep it portable, however, as I said, I use some include. And the asciidoctor.js processes can not resolve them when they are not in the same folder.

Example of file system:
file1.ad
test/file2.ad


file1.ad
Bla bla
include test/file2.ad

test/file2.ad
:imagesdir: ../../src/img/

Bla bla bla
image::test.png[Test]

Then, the image will render for test/file2.ad but it won't for file1.ad as, I guess, it stays in the same path and the :imagesdir: ../../src/img/ then doesn't work.

Am I missing something, do you have a solution for that?
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

mojavelinux
Administrator
> Am I missing something, do you have a solution for that?

Including a file does not change the current directory. You have to think of includes as all the files being combined together and then the result being converted. So they are flat. (Only the include targets themselves are relative to the parent document).

So you would either need to

a) modify the imagesdir in different places in the document, or
b) use a shared image folder with topic folders that mirror the folders you are using for the documents.

I prefer (b). You structure might look like this:

index.adoc
topic-a/
  doc.adoc
topic-b/
  doc.adoc
images/
  topic-a/
    image-for-topic-a-doc.png
  topic-b/
    image-for-topic-b-doc.png

Then, in topic-a/doc.adoc, the image reference would be:

image::topic-a/image-for-topic-a-doc.png[]

At the top of the file, you could define an attribute like:

:topic: topic-a

then reference the image as:

image::{topic}/image-for-topic-a-doc.png[]

or change imagesdir like:

:imagesdir: images/topic-a

then reference the image as:

image::image-for-topic-a-doc.png[]

There are lots of possible solutions. But they all come down to storing the images under a separate hierarchy.

Best Regards,

-Dan

On Sun, Aug 9, 2020 at 4:01 AM yo [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Yes, I would prefer to keep it portable, however, as I said, I use some include. And the asciidoctor.js processes can not resolve them when they are not in the same folder.

Example of file system:
file1.ad
test/file2.ad


file1.ad
Bla bla
include test/file2.ad

test/file2.ad
:imagesdir: ../../src/img/

Bla bla bla
image::test.png[Test]

Then, the image will render for test/file2.ad but it won't for file1.ad as, I guess, it stays in the same path and the :imagesdir: ../../src/img/ then doesn't work.

Am I missing something, do you have a solution for that?


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chrome-Asciidoctor-js-plugin-environment-variables-tp8154p8158.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen (he, him, his) | @mojavelinux | https://twitter.com/mojavelinux
yo
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

yo
Sorry, I am not sure to get it.

I think there are some inaccuracies in your example. Is it not missing some ../image  such as image::topic-a/image-for-topic-a-doc.png[] must be image::../images/topic-a/image-for-topic-a-doc.png[], or :topic: topic-a being :topic: ../images/topic-a? Doesn't matter.

But I think my situation is different as I would like to have a file including another but being in the parent folder as my previous example described:

Example of file system:
file1.ad
test/file2.ad

file1.ad
Bla bla
include test/file2.ad

test/file2.ad
:imagesdir: ../../src/img/

Bla bla bla
image::test.png[Test]

I will need to change a variable at one point in the document but how can I keep both documents to render the image. I need to define at the top of the file2.ad file the imagesdir. Then, including it from another file in a different path will fail.

Sorry if I miss something.
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

mojavelinux
Administrator
The imagesdir never has to reference a parent folder because images are resolved by the generated HTML file. You only have one generated file, so all images are resolved from there.

I think you may need to do some more experimentation. It's hard for me to describe it in more detail.

-Dan

On Sun, Aug 9, 2020, 04:41 yo [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Sorry, I am not sure to get it.

I think there are some inaccuracies in your example. Is it not missing some ../image  such as image::topic-a/image-for-topic-a-doc.png[] must be image::../images/topic-a/image-for-topic-a-doc.png[], or :topic: topic-a being :topic: ../images/topic-a? Doesn't matter.

But I think my situation is different as I would like to have a file including another but being in the parent folder as my previous example described:

Example of file system:
file1.ad
test/file2.ad

file1.ad
Bla bla
include test/file2.ad

test/file2.ad
:imagesdir: ../../src/img/

Bla bla bla
image::test.png[Test]

I will need to change a variable at one point in the document but how can I keep both documents to render the image. I need to define at the top of the file2.ad file the imagesdir. Then, including it from another file in a different path will fail.

Sorry if I miss something.


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chrome-Asciidoctor-js-plugin-environment-variables-tp8154p8160.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML
yo
Reply | Threaded
Open this post in threaded view
|

Re: Chrome Asciidoctor.js plugin environment variables

yo
I think there is a misunderstanding as I agree with what you say and my situation seems very simple.

I have an image in a file that I render thanks to imagesdir. But when I include this file in another file, it works if it is in the same folder and fails otherwise, this is only because of the imagesdir variable declaration in both processes.

So, in the case you include a file that is not in the same folder, how to get these two files render the image correctly ? (The one simply owning the image and the one including this file from another folder)

Thanks for your time.