简体   繁体   中英

failed to load an image when converting html to pdf with pandoc

I use jekyll to generate html files having an image like:

<img src="/assets/images/view.png" alt="" />

When I generate a PDF with pandoc with that HTML, it shows:

Warning: Failed to load file:///assets/images/view.png (ignore)

The resulting PDF doesn't contain the image.

I think that's because the image's path is absolute, it loads from the file system, absolute path. I have tried --resource-path=assets/images/ but doesn't help. Does anyone know how to load images successfully under this case?

There might be a simpler solution, but I'd solve this by using a Lua filter that fixes the image path:

function Image (img)
  -- remove leading slash from image paths
  img.src = img.src:gsub('^/', '')
  return img
end

Save this to a file fix-img.lua and pass the file to pandoc via the --lua-filter option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM