jgm/pandocfilters

get_filename4code should have an accompanying function to get rid of the temporary directories

jerri opened this issue · 4 comments

jerri commented

As far as I understand the code the function get_filename4code is supposed to create a temporary directory to work with files while doing the filtering. Unfortunately there is no suggested function that cleans up the temporary files after filtering. This leads to a lot of pandoc filters to leave directories in the current running pwd that are not really necessary anymore (e.g. mermaid_images, plantuml_images etc.). These files get generated in whatever directory the filter was executed.

On top of the clean-function the code should maybe be impemented by using real tempdir-functionality, thereby creating the files in a temp-directory of the server. Because based on where you start pandoc and what permissions you have in the current directory the current approach can lead to errors, when the directory can't be created, or worse, dirtying of directories that by chance have the same name.

jgm commented

I agree with all of this. However, this project is in a 'barely maintained' state right now. I'm not a Python programmer. If you want to submit a PR, I'd definitely consider this change.
You might also consider panflute, which is a more fully featured and Pythonic library for writing pandoc filters.

ickc commented

Most if not all of the pandocfilters examples are ported to panflute. You can give it a try: https://github.com/sergiocorreia/panflute

I'm not aware of such a helper function in panflute to create temp-dir. (but you should check first.) But you can submit PR there and I can help merging it.

jerri commented

HAHA... :-) "Barely maintained", but two answers within less than 24h. Thanks for your swift feedback.
The reason I point out this topic is, that a lot of pandoc filters are out in the wild based on this library and all suffering this problem of creating unnecessary directories all over the place.
I will check it out and see if I can come up with a PR that at least creates the temporary directory in a sane place. Have to see when I can find time for that.

jerri commented

I created a PR to correct the behaviour. #88