Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua support for resolving files in the data directory #9854

Closed
jeffvalk opened this issue Jun 7, 2024 · 5 comments · Fixed by #9855
Closed

Lua support for resolving files in the data directory #9854

jeffvalk opened this issue Jun 7, 2024 · 5 comments · Fixed by #9855

Comments

@jeffvalk
Copy link

jeffvalk commented Jun 7, 2024

Add Lua support for resolving and reading files from the data directory. At minimum, this should support loading named templates. Ideally, this would enable API access to any type of file stored in the data directory.

From discussion #9853:

It would feel more "batteries included" in the API, and it would give filter/reader/writer authors an indication that they're working with Pandoc's architecture and not against it.

Thoughts:

  1. Add new function get(template_name) to module pandoc.template, which locates the named template in the "templates" directory, and reads and returns its text content, similarly to existing function pandoc.template.default.

  2. Add new function data_file(name) to module pandoc.utils (or elsewhere), which resolves a relative path in the data directory and returns an absolute file path if the file exists, or nil if does not. This would provide a standard mechanism to allow any data directory file to be read, added to the media bag, etc.

tarleb added a commit to tarleb/pandoc that referenced this issue Jun 7, 2024
The function allows to specify a template with the same argument value
that would be used with the `--template` command line parameter.

Closes: jgm#9854
@tarleb
Copy link
Collaborator

tarleb commented Jun 7, 2024

I've opened #9855.

@jeffvalk
Copy link
Author

jeffvalk commented Jun 7, 2024

Awesome.

Do you think item 2 above is worthwhile?

tarleb added a commit to tarleb/pandoc that referenced this issue Jun 7, 2024
The function allows to specify a template with the same argument value
that would be used with the `--template` command line parameter.

Closes: jgm#9854

Co-authored-by: Carsten Gips <cagix@hsbi.de>
@tarleb
Copy link
Collaborator

tarleb commented Jun 7, 2024

I think a read_datafile function or similar would be a useful addition. What's keeping me from adding right away is that, for one, I'm not sure where to place it, as the utils module seems a bit too random for it. The other is that "manually" reading it (or using pandoc.mediabag.fetch) seems less bad for generic data files, and is probably a rarer operation, too.

There's also the generally conservative approach with respect to new Lua functions, as each new functions adds more code to maintain (and compile, and ship), so it's important to only add the "right" functions.

BTW, that's also the reason why I open PRs for these functions instead of just pushing a commit to master, because I want to make sure that "we get it right" with these API changes.

@tarleb
Copy link
Collaborator

tarleb commented Jun 7, 2024

So what I'm trying to say is that I wouldn't rule out data_file, but that the current available mechanisms are acceptable. Adding a function would just be for convenience.

The pandoc.template.get function on the other hand makes the mechanism behind the --template parameter usable in Lua. The parameter uses code that's not necessarily obvious, and is also potentially subject to change. Then the Lua function should change with it. That's why I favor adding that one for now.

@jeffvalk
Copy link
Author

jeffvalk commented Jun 7, 2024

That all makes perfect sense. I had some of the same thoughts, which is why I asked.

tarleb added a commit to tarleb/pandoc that referenced this issue Jun 7, 2024
The function allows to specify a template with the same argument value
that would be used with the `--template` command line parameter.

Closes: jgm#9854

Co-authored-by: Carsten Gips <cagix@hsbi.de>
tarleb added a commit to tarleb/pandoc that referenced this issue Jun 8, 2024
The function allows to specify a template with the same argument value
that would be used with the `--template` command line parameter.

Closes: jgm#9854

Co-authored-by: Carsten Gips <cagix@hsbi.de>
@jgm jgm closed this as completed in #9855 Jun 8, 2024
jgm pushed a commit that referenced this issue Jun 8, 2024
The function allows to specify a template with the same argument value
that would be used with the `--template` command line parameter.

Closes: #9854

Co-authored-by: Carsten Gips <cagix@hsbi.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants