adityarathod / pyandoc

Python wrapper for Pandoc—the universal document converter.
https://pypi.python.org/pypi/pyandoc/
MIT License
213 stars 32 forks source link

pyandoc with citations, pdf, epub, and pandoc executable from path #7

Closed yoavram closed 11 years ago

yoavram commented 11 years ago

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.

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.

wcaleb commented 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.

yoavram commented 11 years ago

@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.

yoavram commented 11 years ago

@kennethreitz is there anything I should do to get this merged? Anything I should change? Just to make sure I didn't miss anything...

kennethreitz commented 11 years ago

:sparkles: :cake: :sparkles:

Thanks so much for this! It looks like a worthy improvement.