Add string to pandoc resources path

Viewed 215

I have some markdown files which reference some images, and I would like to both export these as static html and host them on a website, and also export them locally to PDF via pandoc.

My working directory has my images located in /assets/images/image.png.

The html website requires that the image path be reference exactly like /assets/images/image.png, such that it will locate the image from the root of the website. However, pandoc instead requires assets/images/image.png OR ./assets/images/image.png. As it stand, images cannot be located properly BOTH the website and pandoc.

Is there a way to simply append a string of . in the pandoc resource path options to get around this issue?

1 Answers

Sounds like a job for pandoc's Lua filters. Something along the lines of

-- prepend a slash to all image paths
function Image (img)
  img.src = '/' .. img.src
  return IMG
end

Save the filter to a file and pass it to pandoc via the --lua-filter command line option.

Check out the pandoc.path module if you need to do more complex operations.

Related