-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
I need to define a template variable with multiple values from the command line, via the --variable, but couldn't find any references in pandoc's documentation.
I'm posting this here, as an issue, because I propose adding to the documentation mention of this (wether or not it's possible). And, if it's not possible to do it, I'd like to propose it as a feature request.
Here is the working scenario in detail: I'm using pandoc in a custom CMS workflow to convert markdown documents (with YAML front matter) to html. The CMS engine also autogenerates and passes to pandoc some template vars. Among the autogenerated template vars I wanted to include a breacrumbs variable holding a list of all the folder names that make up the current path to which the document belongs to, and possibly also a string with a description (to be shown as a mouse-over popup on each subfolder name/link, to make better navigation).
Pandoc documentation offers an example of a similar multi-value tempalte variable, using YAML metadata block:
Variables can contain arbitrary YAML structures, but the template must match this structure. The author variable in the default templates expects a simple list or string, but can be changed to support more complicated structures. The following combination, for example, would add an affiliation to the author if one is given:
--- title: The document title author: - name: Author One affiliation: University of Somewhere - name: Author Two affiliation: University of Nowhere ...To use the structured authors in the example above, you would need a custom template:
$for(author)$ $if(author.name)$ $author.name$$if(author.affiliation)$ ($author.affiliation$)$endif$ $else$ $author$ $endif$
... but there is no mentioning if this could be achieve via the command line options -V and -M (neither here nor in the documentation for these options).
So currently I'm using a YAML settings file in each folder to manually handle the breadcrumbs, but the CMS engine could do a better job at autogenerating these vars and pass them via -V and -M — creating an autogenerated temporary YAML file could be a solution, but a rather inelegant one.
Ideally, -V and -M could accept a JSON string to allow defining complex variables. Is it currently possibile? And, if not, could it be implemented?
Furthermore, the above YAML example states further on:
A dot can be used to select a field of a variable that takes an object as its value. So, for example:
$author.name$ ($author.affiliation$)
Again, the documentation for, -M KEY[=VAL] doesn't mention if KEY could be a dot separated field value, or how to define multiple values at once.
I think that handling complex variables via command line is a powerful feature in scripted automation (especially so since variables defined via CLI options have higher priority), and should offer the same features of YAML blocks.