Closed yoavram closed 11 years ago
For what it's worth, I've been testing these changes and they work very well. I'm also relying on the fork by @yoavram in a project of my own:
https://github.com/wcaleb/pandocket
I'd really love to see this merged into the main pyandoc branch.
@wcaleb have a look at Docverter, it's a nice solution for conversion without running pandoc locally. I've written an example of a python script that converts markdown to pdf (using @kennethreitz 's requests library), but it can be easily used with curl
or some other tool, and can convert to numerous formats.
@kennethreitz is there anything I should do to get this merged? Anything I should change? Just to make sure I didn't miss anything...
:sparkles: :cake: :sparkles:
Thanks so much for this! It looks like a worthy improvement.
I've re-forked my previous changes because I changed some files that I shouldn't have (sorry, @kennethreitz!).
The purpose of this fork is to implemented Pandoc's citations and PDF output.
Citations in Markdown
I wanted to use Pandoc for parsing Markdown files with citations. Pandoc supports that by giving a --bibliography=FILE command-line argument with a bibliography file (like .bib). See the Pandoc documentation for more details on that.
But pyandoc did not support that. So I changed it.
PDF and EPUB output
I wanted to output PDF files with Pandoc, but pyandoc outputs to the stdout, and PDFs are generated in Pandoc using LaTeX and therefore must be output to file. So I wrote a new method in pyandoc.Document called _tofile. The method accepts an output filename (with an extention that Pandoc knows, such as pdf or epub). I tested it with PDF and EPUB but it should work for other formats as well. The method works with the bib and all the other stuff mentioned above.
Pandoc executable path
The original project had the path to the pandoc executable hardcoded, and you were supposed to change it after import. But that didn't work for me (got an error - see issue). So I changed the hardcoded path, it is in the file core.py at the top. It is now simply pandoc so you can either change it via _pyandoc.PANDOCPATH or just put pandoc in your path. This solution should work for both Windows and Linux users, I think.
Other details
I tested this on Windows 7 64-bit with Pandoc 1.9.4.2 (running citeproc-hs 0.3.4).
I'm using pyandoc as an alternative HTML renderer for Flask-FlatPages to render blog posts written in Markdown and containing academic citations - see the project here and the module that uses pyandoc to render HTML here.