panflute
panflute copied to clipboard
Autofilter Does Not Honor --data-dir Passed to Pandoc
The auto filter functionality does not recognize when a custom data-dir has been passed in on the command line. It looks like the code has some knowledge and logic to determine the appropriate data-dir, but not in this case. Seems like an easy fix, but I don't know enough about how panflute works to figure out how to get access to pandocs CLI arguments.
input.md
---
title: Title
panflute-filters: [custom_filter]
---
command line
pandoc --data-dir='{data_directory}' --from=markdown --to=html --filter=panflute --output=output.html input.md
where data_directory is like: {data_directory}/filters/custom_filter.py
output
Traceback (most recent call last):
File "/REDACTED/bin/panflute", line 11, in <module>
load_entry_point('panflute==1.12.5', 'console_scripts', 'panflute')()
File "/REDACTED/lib/python3.8/site-packages/panflute/autofilter.py", line 139, in main
stdio()
File "/REDACTED/lib/python3.8/site-packages/panflute/autofilter.py", line 127, in stdio
doc = autorun_filters(filters, doc, search_dirs, verbose)
File "/REDACTED/lib/python3.8/site-packages/panflute/autofilter.py", line 261, in autorun_filters
raise Exception("filter not found: " + filter_)
Exception: filter not found: custom_filter
Error running filter panflute:
Filter returned error status 1
I believe it cannot be fixed. Pandoc does not pass the arg passed to it to the filter. Therefore panflute does not have this information in the first place.
In other words, for this to work, you need someway to pass that information to panflute, Eg via an environment variable. Even if this is implemented, the same arg has to be specified twice, once to pandoc, and then to panflute.
May be I will ask opinion from pandoc-discuss. But for now since this can't be fixed, I'll close this.
Also note from pandoc manual below, may be XDG_DATA_HOME can be search as well.
--data-dir=DIRECTORY Specify the user data directory to search for pandoc data files. If this option is not specified, the default user data directory will be used. On *nix and macOS systems this will be the pandoc subdirectory of the XDG data directory (by default, $HOME/.local/share, overridable by setting the XDG_DATA_HOME environment variable). If that directory does not exist, $HOME/.pandoc will be used (for backwards compatibility). In Windows the default user data directory is C:\Users\USERNAME\AppData\Roaming\pandoc. You can find the default user data directory on your system by looking at the output of pandoc --version. A reference.odt, reference.docx, epub.css, templates, slidy, slideous, or s5 directory placed in this directory will override pandoc’s normal defaults.
c.f. Comments in #142
c.f. #148. There's an env var PANDOC_READER_OPTIONS but does not have info on --data-dir
. So XDG_DATA_HOME is the path to go. Also need to mention that in doc.