Closed adamgordonbell closed 3 years ago
Hi,
Right now you can already control where the plots are saved with the directory
parameter, like so:
#.pandoc-plot.yml
directory: /_site/assets/images/
To have the plots be saved in this directory, but the output document to refer to a different location, increases the complexity of pandoc-plot too much.
The best solution is to create an additional pandoc filter which changes image paths from /_site/assets/images/xyz.png
to /blog/assets/images/xyz.png
. You can refer to the Pandoc documentation on filters to learn how to write filters, either using Lua, Python, or Haskell. Then, you can run pandoc-plot first, and your new filter (e.g.reroute.py
) second like so:
pandoc --filter pandoc-plot --filter reroute.py ....
Here's that rerouting filter in python:
# reroute.py
from pandocfilters import toJSONFilter, Image
path_from = "_site/assets/images/"
path_to = "blog/assets/images/"
def reroute(key, value, format, meta):
if key == 'Image':
attrs, alttext, (url, title) = value
if url.startswith(path_from):
newurl = path_to + url.split(path_from)[-1]
return Image(attrs, alttext, (newurl, title))
if __name__ == "__main__":
toJSONFilter(reroute)
Test file:
# Hello
![This is a test](_site/assets/images/test.png)
command:
pandoc --filter reroute.py -i test.md -o test-reroute.md
Output:
# Hello
![This is a test](blog/assets/images/test.png)
Great, I will give this is a try!
I'm going to close this for now, but don't hesitate to re-open if the solution above does not work.
I didn't try it, because #23 solves this for me, but I expect it would work for my usecase.
Great project. I am using pandoc to generate HTML from markdown for a Jekyll site and trying to use pandoc-plot with it.
To do this I need the output location of the generated image and the HTML path to the image to vary.
For example, config like this would be helpful:
where output_directory is where the image is saved to output_directory, but in the actual HTML it refers to the image using path_to_images. Is this possible?
Here is an example to explain. It is possible I am using it wrong, but it seems like other static site generators would need this feature as well to use pandoc-plot.
Here is what the file structure of a Jekyll site using pandoc might look like:
I can get the images in the correct place like this:
But in the document, the path to the image will be incorrect:
If there were a second config,
path_to_images = /blog/assets/images
the image could go to the same place, but the correct (for this use case) path coudl be in the document: