{ "info": { "author": "Trapeze", "author_email": "tkemenczy@trapeze.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: C", "Programming Language :: Python", "Topic :: Text Processing :: Markup" ], "description": "Discount\n========\n\nThis Python package is a `ctypes`_ binding of `David Loren`_'s\n`Discount`_, a C implementation of `John Gruber`_'s `Markdown`_.\n\n.. _`ctypes`: http://docs.python.org/library/ctypes.html\n.. _`David Loren`: http://www.pell.portland.or.us/~orc\n.. _`Discount`: http://www.pell.portland.or.us/~orc/Code/discount/\n.. _`John Gruber`: http://daringfireball.net/\n.. _`Markdown`: http://daringfireball.net/projects/markdown\n\n.. contents::\n\n\nIntroduction\n------------\n\nMarkdown is a text-to-HTML conversion tool for web writers. Markdown\nallows you to write using an easy-to-read, easy-to-write plain text\nformat, then convert it to structurally valid XHTML (or HTML).\n\nThe ``discount`` Python module contains two things of interest:\n\n* ``libmarkdown``, a submodule that provides access to the public C\n functions defined by Discount.\n\n* ``Markdown``, a helper class built on top of ``libmarkdown``,\n providing a more familiar Pythonic interface\n\n\nUsing the ``Markdown`` class\n----------------------------\n\nThe ``Markdown`` class wraps the C functions exposed in the\n``libmarkdown`` submodule and handles the ctypes leg work for you. If\nyou want to use the Discount functions directly, skip to the next\nsection about ``libmarkdown``.\n\nLet's take a look at a simple example::\n\n import sys\n import discount\n\n mkd = discount.Markdown(sys.stdin)\n mkd.write_html_content(sys.stdout)\n\n\n``Markdown`` takes one required argument, ``input_file_or_string``,\nwhich is either a file object or a string-like object.\n\n **Note:** There are limitations to what kind of file-like objects\n can be passed to ``Markdown``. File-like objects like\n ``StringIO`` can't be handled at the C level in the same way as OS\n file objects like ``sys.stdin`` and ``sys.stdout``, or file\n objects returned by the builtin ``open()`` method.\n\n``Markdown`` also has methods for getting the output as a string,\ninstead of writing to a file-like object. Let's look at a modified\nversion of the first example, this time using strings::\n\n import discount\n\n mkd = discount.Markdown('`test`')\n print mkd.get_html_content()\n\nCurrently, ``Markdown`` does not manage character encoding, since the\n``Markdown`` wraps C functions that support any character encoding\nthat is a superset of ASCII. However, when working with unicode\nobjects in Python, you will need to pass them as bytestrings to\n``Markdown``, and then convert them back to unicode afterwards. Here\nis an example of how you could do this::\n\n import discount\n\n txt = u'\\xeb' # a unicode character, an e with an umlaut\n mkd = discount.Markdown(txt.encode('utf-8'))\n out = mkd.get_html_content()\n val = out.decode('utf-8')\n\nThe ``Markdown`` class constructor also takes optional boolean keyword\narguments that map to Discount flags compilation flags.\n\n``toc``\n Generate table-of-contents headers (each generated