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

Allow defaults file to be specified in YAML header #7977

Closed
diktomat opened this issue Mar 20, 2022 · 5 comments
Closed

Allow defaults file to be specified in YAML header #7977

diktomat opened this issue Mar 20, 2022 · 5 comments

Comments

@diktomat
Copy link

diktomat commented Mar 20, 2022

To use defaults files for specifying templates etc., the only possible way currently is using the command line option. This poses problems for using from within editors (like Zettlr or as makeprg in Vim), as one has to add specific command line options (-d foo) for every file. If a defaults: key in a file's YAML header was allowed (maybe only with --defaults-from-infile or similar for security reasons), it could stand alone and customizing the Pandoc command line for every type of file would only still be necessary for edge cases.

This was already discussed in this comment and following, but as #5870 is basically the opposite request and there is no response by @jgm on this topic, I'm opening a separate issue for what I consider to be a separate request.

Sample

---
title: Why Pandoc is great
author: Me, obviously
defaults: presentation
---

It just is!

or

---
title: Thesis
author: me, again
defaults: thesis
---

In a not to far future …

Alternatives

There are tools like pandocomatic or panrun, which are much more powerful, but most times this power is not needed. Also, imo there should be no need for a third party tool for such a simple task.

For nVim, I created this pandoc.lua compiler plugin, which does exactly what I propose above, but only in Neovim:

local defaults = vim.fn.matchlist(vim.fn.getline(vim.fn.search('^defaults:', 'n')), '^defaults:\\s*\\(.*\\)$')[2]
defaults = defaults and ' -d '..defaults or ''
vim.bo.makeprg = 'pandoc' .. defaults .. ' -o "%:p:r.pdf" "%:p"'
@jgm
Copy link
Owner

jgm commented Mar 20, 2022

The proposal is already discussed in #5870. Conceptually, this doesn't make sense, I think, because one of the things the defaults file can specify is whether the input format is markdown and whether YAML headers are supported... There are also security implications.

Of course, nothing prevents you from calling pandoc from a wrapper script that examines the front matter and calls pandoc with the appropriate defaults file -- as you have done yourself.

@jgm jgm closed this as completed Mar 20, 2022
@diktomat
Copy link
Author

I know, but #5870 is originally on another topic, so I thought it’d make sense to separate these. While obviously specifying whether to parse yaml headers after parsing them is bogus, I see it more like \documentclass in LaTeX, a way to say what type of document this is.

Nonetheless, as you say, I’ll continue using my wrapper in Vim and other software supporting such things. And have unnecessary manual overhead in software that doesn’t…

@jgm
Copy link
Owner

jgm commented Mar 20, 2022

I see it more like \documentclass in LaTeX, a way to say what type of document this is.

But note that LaTeX's \documentclass does not allow you to specify that the document is an HTML document! If you could specify defaults or a defaults file in a Markdown file, the defaults could specify that the input format is HTML or some other format than Markdown. So I don't think it's very parallel.

@diktomat
Copy link
Author

But how is that different from being able to do pandoc --from html something.md, which also won’t produce anything useful. One just doesn‘t do it.

@camoz
Copy link

camoz commented Feb 14, 2024

I concur with @d12bb here. Also, adding to the previous comment, how is it different from pandoc --defaults defaults.yaml input.md where defaults.yaml could set conflicting from:/to: values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants