Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images in tables are not pulled into the archive #5

Closed
LightGuard opened this issue Jul 30, 2014 · 7 comments
Closed

images in tables are not pulled into the archive #5

LightGuard opened this issue Jul 30, 2014 · 7 comments
Assignees
Labels

Comments

@LightGuard
Copy link
Member

You can recreate this by building the book at vromero/mule-doc@4eed0f1. The list discussion is at http://discuss.asciidoctor.org/Asciidoc-EPUB3-and-local-images-td1936.html

@mojavelinux
Copy link
Member

There are two sources of this problem. First, the converter does not pull in inline images because they aren't available in the AST after a parse atm. If the images are changed to be block images, then it still won't find them because find_by doesn't currently look in AsciiDoc table cells.

Here are the lines in question:

@mojavelinux mojavelinux added this to the v1.0.0 milestone Jul 30, 2014
@mojavelinux
Copy link
Member

For now, here's the logic that's needed.

images = (doc.find_by context: :image).concat doc.find_by(context: :table).map {|table|
  table.rows.body.flatten.select {|cell| cell.style == :asciidoc }
}.flatten.map {|cell|
  cell.instance_variable_get(:@inner_document).find_by(context: :image)
}.flatten

@mojavelinux
Copy link
Member

I suppose we'll eventually want to support this in find_by, but it's definitely a rough-in. For now, it might be best just to put it in asciidoctor-epub3 as a stop-gap measure.

@mojavelinux mojavelinux self-assigned this Oct 13, 2014
@mojavelinux
Copy link
Member

Feel free to attempt a patch if you get to it before me.

@mojavelinux mojavelinux modified the milestones: v1.5.0.alpha.8, v1.5.0 Apr 9, 2017
@mojavelinux
Copy link
Member

I've decided to solve this by using the document catalog instead of the AST. We already have the limitation that the imagesdir cannot be changed within a chapter file, so we have enough information to be able to reconstruct the path to the image from the value in document catalog alone.

In order to make this work, we have to set the catalog_assets option on the document to true. Fortunately, we control the loading of each chapter file in the spine processor, so we can set additional options. (See

spine_item_doc = ::Asciidoctor.load_file include_file,
# setting base_dir breaks if outdir is not a subdirectory of spine_doc.base_dir
#base_dir: spine_doc.base_dir,
# NOTE won't write to correct directory if safe mode is :secure
safe: spine_doc.safe,
backend: 'epub3-xhtml5',
doctype: :article,
header_footer: true,
attributes: inherited_attrs
).

One problem we're going to run into is that, as of 1.5.6.1, core does not pass the catalog_assets option to nested documents (e.g., an AsciiDoc table cell). There's no easy way around this limitation. Therefore, images in AsciiDoc table cells will not be included until that is fixed in core (slated for 1.5.7).

@mojavelinux
Copy link
Member

I also needed to add SVG support for inline images in the converter and set a max-width value for inline images. I decided to add the class inline to inline images to help distinguish them from block / figure images in the stylesheet.

mojavelinux added a commit to mojavelinux/asciidoctor-epub3 that referenced this issue Feb 16, 2018
* enable catalog_assets option on documents in spine
* read images from catalog (i.e., references) table
* move call to add_content_images method inside add_content method
* add svg to epub properties list if an inline SVG image is detected
* set width of inline image to value of scaledwidth attribute, if specified
 ** if scaledwidth attribute is not specified and image is an SVG, set value to 100%
* add inline class to inline image elements
* add max-width: 100% style to all images (not just figures)
* group figure.image styles together in stylesheet
@mojavelinux
Copy link
Member

mojavelinux commented Feb 17, 2018

Please note if you are reading this that images in AsciiDoc table cells will not be included unless you are using at least Asciidoctor (core) 1.5.7 (and it has been released, of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants