Pypandoc not accepting yml input

306 Views Asked by At

I am able to compile an invoice with the following command:

pandoc details.yml -o output.pdf --template=invoice.tex --latex-engine=xelatex

But when I write the same thing in Python, I get an error complaning about the input format:

>>> pypandoc.convert_file('details.yml', 'pdf', outputfile='pyout.pdf', extra_args=['--latex-engine=xelatex', '--template=invoice.tex'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 140, in convert_file
    outputfile=outputfile, filters=filters)
  File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 262, in _convert_input
    format, to = _validate_formats(format, to, outputfile)
  File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 223, in _validate_formats
    _get_base_format(format), ', '.join(from_formats)))
RuntimeError: Invalid input format! Got "yml" but expected one of 
these: commonmark, docbook, docx, epub, haddock, html, json, latex, markdown, markdown_github, markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, native, odt, opml, org, rst, t2t, textile, twiki

What am I doing wrong here? Why is yml not accepted?

1

There are 1 best solutions below

0
On BEST ANSWER

Figured it out by reading the source.

So it turns out that this is due to a design decision made by the pypandoc developers. The program infers the type of the input from the file extension, so the only way to pass a yaml file is to rename it with a .md-extension.

https://github.com/bebraw/pypandoc/blob/ffe82646d2ab6cc4e732960a1e1af6bfcb760bb1/pypandoc/init.py#L202