Replies: 9 comments 24 replies
-
This sounds interesting. Note, however, that you can already achieve this by altering the value of the variable package.path (see the Lua manual) like this:
package.path = package.path .. ';' .. PANDOC_STATE.user_data_dir .. '/filters/my-filter/?.lua'
|
Beta Was this translation helpful? Give feedback.
-
Thanks @badumont for your comment. I'm not sure how your suggestion would solve the problem though. Perhaps I didn't do a great job explaining the situation, or I misunderstood something. To clarify, let's say I have a filter repository This is quite lengthy, and it would be nice to be able to simply do Changing |
Beta Was this translation helpful? Give feedback.
-
To clarify, let's say I have a filter repository `filter-name` with a bunch of Lua files, and one top level filter file `filter-name/filter.lua`, which loads the other Lua files. If I now copy or clone the repository to `~/.local/share/pandoc/filters/filter-name` in order to make the filter available to pandoc, and I want to call this filter, I need to do so via `--lua-filter=filter-name/filter.lua`.
Actually there are two issues here, a feature request and a problem that can be worked around (and that I believed was implied in your first message). For the feature request, you will have to wait until it is (maybe) implemented. The problem I addressed is that, when other Lua files are required from `filter-name.lua`, the Lua engine embedded in Pandoc cannot find them because it does not search them under the Pandoc user directory. By setting pandoc.path as I suggested, you can set your file `filter-name.lua` juste under `~/.local/share/pandoc/filters` and the dependent files under a subdirectory thereof, so that you can use your filter with `pandoc -L filter-name.lua` and it will find its required files under `~/.local/share/pandoc/filters/filter-name`.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification @badumont. Regarding the feature request, I'm happy to implement this myself. The purpose of this discussion is to ascertain whether this would be a desirable feature, and if there is appetite to have a corresponding PR merged, or if someone has a better idea. Regarding how to require the other Lua files, there are a few options. Adding |
Beta Was this translation helpful? Give feedback.
-
This sounds reasonable to me. @tarleb any thoughts? |
Beta Was this translation helpful? Give feedback.
-
The Lua default when loading packages is to look for I lean towards using |
Beta Was this translation helpful? Give feedback.
-
About The additional benefit of having a |
Beta Was this translation helpful? Give feedback.
-
If we go with the On another note, this concept could perhaps be expanded further by letting pandoc search the entire |
Beta Was this translation helpful? Give feedback.
-
FWIW, I've encountered the same issue (preference to split a filter in multiple source files). My solution has been to use Lua code combine to write a filter as multiple files, but distribute it in a single file. See e.g. this filter. This solution works out of the box with Quarto as well as Pandoc, and is probably easier for other users if you share your filter. I wrote a fork of Tarleb's lua filter template that handles creating a single Lua filter from multiple source files. It's not documented yet, but the comments in the Makefile should clarify how it works. Whenever you run |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When I write Lua filters, I may want to split up the filter code into several Lua files to group functionality, when one file becomes too unwieldy. To use the filter, I can then no longer simply copy just one filter file to
~/.local/share/pandoc/filters
and run it viapandoc -L filter-name.lua
. I need to copy the whole repository to that directory and call it viapandoc -L filter-name/filter.lua
.This, however, doesn't seem very elegant. For that reason I thought perhaps we could implement the following convention in pandoc: If the Lua filter called does not end in
.lua
, e.g.pandoc -L filter-name
, pandoc would search for a file~/.local/share/pandoc/filters/filter-name/filter.lua
instead (and in the current directory of course). Keen to hear your thoughts on this proposal!Beta Was this translation helpful? Give feedback.
All reactions