我可以使用以下命令编译发票:
pandoc details.yml -o output.pdf --template=invoice.tex --latex-engine=xelatex
但是当我用 Python 编写同样的东西时,我收到一个关于输入格式的错误:
>>> 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
我在这里做错了什么?为什么不接受 yml?
通过阅读源代码弄清楚了。
因此,事实证明,这是由于pypandoc开发人员做出的设计决策。该程序从文件扩展名推断输入的类型,因此传递yaml文件的唯一方法是使用.md扩展名重命名它。
https://github.com/bebraw/pypandoc/blob/ffe82646d2ab6cc4e732960a1e1af6bfcb760bb1/pypandoc/init.py#L202