Hi Jens, Stuart,

I just went for a walk around the block and I think I now understand
it so let me present the current situation in excruciating detail, and
Stuart can correct as appropriate.

Starting with data-uri set, this is easy since the image path is only
used for an input because the image is embedded.  The target is
relative to the directory of the input file (or output if input is not
from a file) with imagesdir interposed if defined.  Imagedir and
target can be relative or absolute, it doesn't matter since its just
read for creation of the embedded data.  Being relative to the input
file (the one containing the image:: even if its included in another
document) supports subdocuments being processed alone or as part of
the aggregate document.

Fine so far.

With data-uri not set asciidoc must generate links to the image files.
 As Stuart pointed out there are situations where links to absolute
paths will not work, so its reasonable for asciidoc to only generate
relative links.  These links must be relative to the *output* file so
the browser/server can find them.  As Stuart pointed out it is
potentially difficult to generate these from an input file path, so in
fact the user must specify the link contents in imagesdir/ (if
defined) and target.  This isn't really clearly pointed out in the
docs I don't think.

The data-uri and non-data-uri situations are in fact specifying
different things and thats why they are different.  In most cases
nobody notices since in most cases indir and outdir are the same or
only data-uri or links are used, its only in the case of documents
processed both with and without data-uri and in more than one
directory that the problem occurs.  Since this is the unusual use-case
I think asciidoc should be left as is and alternate solutions
considered.

So one solution is that indir must be the same as outdir in all cases,
ie all asciidoc and output files must be in the one dir:

whole_doc.asciidoc
whole_doc.html
chapter_1.asciidoc
chapter1.html
chapter_2.asciidoc
chapter_2.html
etc
chapter1_images/image_1.png
chapter1_images/image_2.png
chapter2_images/image_3.png

Note that the images can still be separated in subdirectories but that
asciidoc files must be in the same location.

If having everything in the top level is too messy, then try the directory tree:

whole_doc.asciidoc
whole_doc.html
chapter1/contents.asciidoc
chapter1/contents.html
chapter1/images/image1.png
chapter1/images/image2.png
etc

For this to work, subdocuments must set imagesdir to adjust for the
case of a non-datauri whole document. Now the subdocuments must know
if they are being processed on their own or in the whole document, so
in whole_doc.asciidoc define an attribute, say :whole_doc:

Subdocuments reference images as image::images/image1.png[] and at the
top each of them has:

ifdef::whole_doc[]
ifndef::data-uri[]
:imagesdir: chapter1
endif::data-uri[]
endif::whole_doc[]

If whole_doc.asciidoc has any image macros the it will have to
undefine imagesdir after each include or each subdocument should
undefine it at its end.

Cheers
Lex

On 16 January 2013 19:30, gmail <[email protected]> wrote:
> Hello Stuart,
>
> Le 15/01/2013 00:02, Stuart Rackham a écrit :
>
> A work-around is to use the {@::} conditional attribute to substitute
> one path if indir == docdir (i.e. is root document) or another path if
> not (i.e. is an included sub-document) e.g.
>
> image::{indir@{docdir}::doc/}picture.png[]
>
> The src is picture.png if root document else doc/picture.png if included.
>
>
> Thank you for this workaround, but I do not think that it helps a lot (see
> below).
>
> This is the expected behaviour:
>
>>> lstree
> ./main.asciidoc
> ./part1/chapter.asciidoc
> ./part1/images/photo1.png
>
>>>cat ./main.asciidoc
> :leveloffset: 1
> :data-uri:
> include::./part1/chapter.asciidoc[]
>
>>>cat ./part1/chapter.asciidoc
> image::./images/photo1.png[]
>
>
> Unfortunately not all backends interpret the imagepath in subdocuments the
> same way. And it depends if :data-uri: is set or not.
>
> I don't think that your workaround helps as long as the starting point of
> imagepaths in subdocuments sometimes refer to the main document's directory
> and sometimes to the subdocument's directory. For example if :data-uri: is
> not set one has to write
>         image::./chapter1/images/photo1.png[]
> in the subdocument instead.
>
> Wouldn't it be the simplest and best solution to correct to code in backends
> that imagepaths behave in a same consistent way as shown above, whether
> :data-uri: is enabled or not?
>
> Best regards
>
>
>
> Jens
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "asciidoc" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/asciidoc?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

Reply via email to