Skip to main content

Pandoc Documents for Python

Project description

Pandoc (Python Library)

PyPi Python Status Travis CI Build Status AppVeyor Build status

A Pythonic Version of Pandoc

Pandoc is the "document swiss army knife" made by John MacFarlane. It brings:

  • a command-line tool,

  • a Haskell library,

  • a document (meta-)model.

If you only need to convert some documents from one format into another (say Markdown to HTML or Markdown to PDF), the command line tool is what you need. But if additionally you need to analyze, create or transform documents, you may find this Python library useful, especially if you're proficient in Python but don't know Haskell.

The basic process is the following:

  1. First, create a document; for example, read a Markdown text

    >>> import pandoc
    >>> markdown = "Hello"
    >>> doc = pandoc.read(markdown)
    >>> doc
    Pandoc(Meta(map()), [Para([Str(u'Hello!')])])
    
  2. Then, analyze and/or transform the document as you like

    >>> from pandoc.types import *
    >>> para = doc[1][0]
    >>> para
    Para([Str(u'Hello')])
    >>> contents = para[0]
    >>> contents
    [Str(u'Hello')]
    >>> contents.extend([Space(), Str("World!")])
    >>> doc
    Pandoc(Meta(map()), [Para([Str(u'Hello'), Space(), Str('World')])])
    
  3. Finally, output the new document as Markdown

    >>> pandoc.write(doc)
    u'Hello World\n'
    

    and optionally, generate its HTML version

    >>> pandoc.write(doc, file="doc.html")
    u'<p>Hello World</p>\n'
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pandoc, version 2.0a2
Filename, size File type Python version Upload date Hashes
Filename, size pandoc-2.0a2.tar.gz (37.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page