Reputation: 6558
In order to specify an output format for pandoc, I must set the -t
flag on the command line. I would like to specify which output format I want from inside of my Markdown text file. Is this possible?
For instance, if I wanted pandoc to convert my Markdown text file to a Microsoft Word document, I imagine it might look like this:
mydocument.md:
---
title: Not Just Good, More Good
author: DanielTA
date: 9 September 2022
geometry: margin=1in
mainfont: Comic Neue
fontsize: 12pt
output: docx
---
Document body text...
Then run pandoc mydocument.md
which would output mydocument.docx
into the same directory.
I tried this and it does not seem to work. I know that many command line variables can be defined in the YAML metablock header, but I am not sure if format/output options are possible to define there.
Upvotes: 3
Views: 814
Reputation: 172
That should be easy to implement with lua writer using pandoc.write
function.
function Writer (doc, opts)
local fmt = doc.meta.output[1].text
local template = pandoc.template
opts.template = template.compile(template.default(fmt))
return pandoc.write(doc, fmt, opts)
end
function Template ()
return""
end
And this works as expected for most of the formats. But not with "docx".
Upvotes: 0
Reputation: 22609
It's not possible to define this kind of information in the metadata. However, pandoc has a feature called "defaults files". Input and output formats, options, and filenames can all be put there. The file is then passed to pandoc via --defaults
or -D
.
pandoc -D docx.yaml mydocument.md
Alternatively, take a look at Quarto. It is a beautiful system based on pandoc and allows to incorporate this kind of info directly in the YAML frontmatter.
Upvotes: 1