-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Problem
The Pandoc filter documentation includes an example on how to include external files in a document. I currently have a similar problem—I'm writing a filter which inlines SVGs for HTML output (it checks if images in the markdown source have a .svg extension and replaces the image with a RawInline containing the SVG's contents). This requires finding and loading the SVG file. When the markdown source file is in the same directory, everything works fine:
file.md:
---
title: A Test
---
$ pandoc file.md -f markdown -t html --filter my-filter -o dir/output.html
However, if the markdown file is not in the working directory, the filter expectedly cannot find the SVG file, since its path is relative, not absolute, and the filter is executed from the working directory, not the document directory:
$ pandoc dir/file.md -f markdown -t html --filter my-filter -o output.html
Error printed by my-filter: Cannot find file test.svg!
The same issue would occur in the example in the documentation if the markdown file to be processed was in another directory.
Describe your proposed improvement
There should be a mechanism to let filters know the document's path relative to the working directory. That way, if a file referenced in file.md was using a relative path, the correct path relative to the working directory could be computed by the filter. I propose to add an environment variable titled something along the lines of RELATIVE_PATH_TO_DOC to the environment variables set by Pandoc before calling a filter.
Describe alternatives you've considered
I tried using the rebase_relative_paths extension, but this would not actually solve the problem, as any files not processed by the filter would have incorrect paths when executing pandoc as follows:
$ pandoc dir/file.md -f markdown+rebase_relative_paths -t html --filter my-filter -o dir/output.html
If dir/file.md contains an image that is not an SVG (), it will have an incorrect path in the HTML output (dir/test.jpg instead of test.jpg).