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

Remote image url failed to load. #415

Open
rshiva opened this issue Mar 31, 2022 · 8 comments
Open

Remote image url failed to load. #415

rshiva opened this issue Mar 31, 2022 · 8 comments
Labels

Comments

@rshiva
Copy link

rshiva commented Mar 31, 2022

Asciidoctors,
I'm unable to generate/view the image from a remote URL while generating the Mobi. Whereas it works for asciidoctor when converting adoc to HTML

Code look something like this

image::https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Tux,250,350]

You can find image:https://upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg[Linux,25,35] everywhere these days.
asciidoctor-epub3 -D output -a ebook-format=kf8 chapter1.adoc --trace

asciidoctor-epub3 -D output -a ebook-format=kf8 chapter1.adoc --trace
asciidoctor: WARNING: Warning(svgparser):W25001: SVG Parser could not find the referenced file  /var/folders/lk/4m5qlr251kn__x7p13nsbhcc0000gn/T/mobi-o0n9Ff/EPUB/https:/upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg
asciidoctor: WARNING: Warning(prcgen):W14010: media file not found  /var/folders/lk/4m5qlr251kn__x7p13nsbhcc0000gn/T/mobi-o0n9Ff/EPUB/https:/upload.wikimedia.org/wikipedia/commons/3/35/Tux.svg
asciidoctor: ERROR: Error(prcgen):E21018: Enhanced Mobi building failure, while parsing content in the file. Content: <You can find image::> in file: /var/folders/lk/4m5qlr251kn__x7p13nsbhcc0000gn/T/mobi-o0n9Ff/EPUB/preamble.xhtml line: 24
asciidoctor: ERROR: KindleGen failed to write MOBI to /Users/shiva/workspace/kindle-book-generator/first-book/new-book/output/chapter1.mobi

Am I missing something? Please guide I'm totally new to Asciidoctor. This #333 issue says remote URL issue is resolved

@slonopotamus
Copy link
Contributor

I'm not sure Mobi supports remote images at all. In #333, asciidoctor-epub3 was fixed to pass URLs to EPUB. Mobi is created from EPUB using KindleGen and looks like the latter doesn't support remote URLs. We could add some hacks like "if we are producing Mobi, download remote resource and use that". The problem is that is isn't very clear when to download. Should we do it on each and every conversion? Or we should cache file? But when to re-download it?

@rshiva
Copy link
Author

rshiva commented Apr 1, 2022

Thanks for the quick reply. Is it possible, whenever a URL is provided we download the images from the URL and put in a temporary folder or cache then read the images from there to create the Mobi and delete the cache after converting. I think it would make sense to download the images on every conversion.
@slonopotamus Thanks for your contribution 😄

@slonopotamus
Copy link
Contributor

We should not reinvent the wheel and just implement this logic: https://docs.asciidoctor.org/asciidoc/latest/directives/include-uri/

@slonopotamus
Copy link
Contributor

Hmm... Looks like we already can do that:

asciidoctor-epub3 -D output -a ebook-format=kf8 -a data-uri -a allow-uri-read chapter1.adoc

@rshiva does this work for you?

Note that you cannot use SVG images because Mobi doesn't support that.

@slonopotamus slonopotamus added question and removed bug labels Apr 3, 2022
@mojavelinux
Copy link
Member

The logic to fetch a remote image, and to even cache it, is already provided by Asciidoctor core. See this method: https://github.com/asciidoctor/asciidoctor/blob/main/lib/asciidoctor/abstract_node.rb#L322-L334

The downside of that method is that it returns the image as a data URI instead of as a File reference. However, you can find a different implementation in Asciidoctor PDF that returns a temporary file path: https://github.com/asciidoctor/asciidoctor-pdf/blob/main/lib/asciidoctor/pdf/converter.rb#L4240-L4259

Suffice to say, this is a solved problem in Asciidoctor. It's just a matter of reusing the code which is already available.

@mojavelinux
Copy link
Member

-a data-uri

Indeed, this is one approach that leverages the logic I linked to in Asciidoctor core. If you prefer to have it add the image files to the manifest, then you would need the code from Asciidoctor PDF.

@slonopotamus
Copy link
Contributor

Yep, there are some downsides using -a data-uri, but it might be Good Enough as a quick-and-dirty workaround.

@rshiva
Copy link
Author

rshiva commented Apr 4, 2022

Hmm... Looks like we already can do that:

asciidoctor-epub3 -D output -a ebook-format=kf8 -a data-uri -a allow-uri-read chapter1.adoc

@rshiva does this work for you?

Note that you cannot use SVG images because Mobi doesn't support that.

Thanks @mojavelinux and @slonopotamus this worked

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

3 participants