How to add images in hex package documentation with exdoc

Hi,
I generated Docs using the exdoc module.
The index.html is showing the images when I checked offline,but when I publish to the
HEX Package Manager images are not showing.
is anything to add more ?
if not possible with exdoc please specify an alternative.

Screenshot

Thanks in Advance :bouquet:

3 Likes

As a workaround it should be possible to have the pictures hosted on an external service, eg github-pages. But of course you are right, it would be nice if hexdocs.pm would have better suipport or at least an official statement about this.

Perhgaps we pull @ericmj in here if this is worth to open an issue at https://github.com/hexpm/hex_web/issues or if this is by design?

Images should work on hexdocs. Can you link to your project and show how you copied the images, generated the docs and added the images to the markdown?

I have added the image links in the @doc section while writing the definitions in the module and I used exdoc mix docs to generate the docs.
It generated a folder with doc and holding all the stuff files .
This is the github link
You can find the doc folder there.
Thanks for quick reply :bouquet:

You need to put the images inside the doc/ directory. Hex only pushes things inside that directory to hexdocs [1], we do not traverse the markdown to resolve links to resources anywhere on your filesystem. You might also want to copy the images inside an alias [2] on the docs task that runs after ex_doc to ensure that ex_doc does not overwrite the directory:

defp aliases do
  [docs: ["docs", &copy_images/1]]
end

defp copy_images(_) do
  File.cp! ...
end

[1] https://hex.pm/docs/tasks#hex_publish
[2] https://hexdocs.pm/mix/Mix.html#module-aliases

6 Likes

Thanks for the quick response. The above one only works to copy contents of one file to another.After looking into more with your suggestions I found the follwing code snippets which copy the contents of source to destination in the official docs

defp copy_images(_) do
   File.cp_r "source", "destination", fn(source, destination) ->
   IO.gets("Overwriting #{destination} by #{source}. Type y to confirm. ") == "y\n"
   end
end

That really solved the problem. Thanks for that amazing stuff. Now Images are shown in the docs.
The Printex Documentation
:bouquet: :bouquet: Once again Thanks a lot.