{ "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

,

,\n etc will include a id=\"name\" argument.) Use ``get_html_toc()``\n or ``write_html_toc()`` to generate the table-of-contents\n itself.\n\n``strict``\n Disable relaxed emphasis and superscripts.\n\n``autolink``\n Greedily expand links; if a url is encountered, convert it to a\n hyperlink even if it isn't surrounded with ``<>s``.\n\n``safelink``\n Be paranoid about how ``[][]`` is expanded into a link - if the\n url isn't a local reference, ``http://``, ``https://``,\n ``ftp://``, or ``news://``, it will not be converted into a\n hyperlink.\n\n``ignore_header``\n Do not process the `pandoc document header`_, but treat it like\n regular text.\n\n``ignore_links``\n Do not allow ```` tags, and the second lets you add additional\nHTML attributes on ```` tags generated by Discount. You can pass\ncallback functions to ``Markdown``'s ``rewrite_links_func`` and\n``link_attrs_func`` keyword arguments respectively.\n\nHere is an example of a callback function that adds the domain name to\ninternal pages::\n\n def add_basepath(url):\n if url.startswith('/'):\n return 'http://example.com%s' % url\n\n md = Markdown(\n '`[a](/a.html)`',\n rewrite_links_func=add_basepath\n )\n\nHere is an example that opens external pages in another window/tab::\n\n def add_target_blank(url):\n if url.startswith('http://'):\n return 'target=\"_blank\"'\n\n md = Markdown(\n '`[a](http://example.com/a.html)`',\n link_attrs_func=add_target_blank\n )\n\nAlternatively, you can attach these callbacks using decorators::\n\n md = Markdown('`[a](/a.html)`')\n\n @md.rewrite_links\n def add_basepath(url):\n # same as above\n ...\n\n md = Markdown('`[a](http://example.com/a.html)`')\n\n @md.link_attrs\n def add_target_blank(url):\n # same as above\n ...\n\nUnder some conditions, the functions in ``libmarkdown`` may return\ninteger error codes. These errors are raised as a ``MarkdownError``\nexceptions when using the ``Markdown`` class.\n\n.. _`pandoc document header`:\n http://johnmacfarlane.net/pandoc/README.html#title-blocks\n.. _`PHP Markdown Extra`:\n http://michelf.com/projects/php-markdown/extra/.\n.. _`SmartyPants`:\n http://daringfireball.net/projects/smartypants/\n.. _`pseudo-protocols`:\n http://www.pell.portland.or.us/~orc/Code/discount/#pseudo\n\n\nUsing ``libmarkdown``\n---------------------\n\nIf you are familiar with using the C library and would rather use\nDiscount library directly, ``libmarkdown`` is what you are looking\nfor; it's simply a thin wrapper around the original C implementation.\n``libmarkdown`` exposes the public functions and flags documented on\nthe `Discount homepage`_.\n\nIn Python you'll need to do some extra work preparing Python objects\nyou want to pass to ``libmarkdown``'s functions.\n\nMost of these functions accept ``FILE*`` and ``char**`` types as their\narguments, which require some additional ctypes boilerplate.\n\nTo get a ``FILE*`` from a Python file descriptor for use with\n``libmarkdown``, use the following pattern::\n\n i = ctypes.pythonapi.PyFile_AsFile(sys.stdin)\n o = ctypes.pythonapi.PyFile_AsFile(sys.stdout)\n doc = libmarkdown.mkd_in(i, 0)\n libmarkdown.markdown(doc, o, 0))\n\nFor ``libmarkdown`` functions to which you pass a ``char**``, use the\nfollowing pattern::\n\n cp = ctypes.c_char_p('')\n ln = libmarkdown.mkd_document(doc, ctypes.byref(cp))\n html_text = cp.value[:ln]\n\nIt is important to initialize ``c_char_p`` with an empty string.\n\n.. _`Discount homepage`:\n http://www.pell.portland.or.us/~orc/Code/discount/\n\n\nRunning the test suite\n----------------------\n\nTests are available with the source distibution of ``discount`` in the\n``tests.py`` file. The C shared object should be compiled first::\n\n python setup.py build_ext\n\nThen you can run the tests::\n\n python tests.py\n\n\nSource code and reporting bugs\n------------------------------\n\nYou can obtain the source code and report bugs on\n`GitHub project page`_.\n\n.. _`GitHub project page`:\n http://github.com/trapeze/python-discount/issues\n\n\nLicense\n-------\n\nSee the ``LICENSE`` file in the source distribution for details.\n\n\nCredits\n-------\n\n``discount`` is maintained by `Tamas Kemenczy`_, and is funded by\n`Trapeze`_. The `Discount`_ C library is written and maintained by\n`David Loren`_ and contributors. See the ``AUTHORS`` file for\ndetails.\n\n.. _`Tamas Kemenczy`: mailto:tkemenczy@trapeze.com\n.. _`Trapeze`: http://trapeze.com\n.. _`Discount`: http://www.pell.portland.or.us/~orc/Code/discount/\n.. _`David Loren`: http://www.pell.portland.or.us/~orc", "description_content_type": null, "docs_url": null, "download_url": "http://pypi.python.org/pypi/discount", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/trapeze/python-discount", "keywords": "markdown discount ctypes", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "discount", "package_url": "https://pypi.org/project/discount/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/discount/", "project_urls": { "Download": "http://pypi.python.org/pypi/discount", "Homepage": "http://github.com/trapeze/python-discount" }, "release_url": "https://pypi.org/project/discount/0.2.1STABLE/", "requires_dist": null, "requires_python": null, "summary": "A Python interface for Discount, the C Markdown parser", "version": "0.2.1STABLE" }, "last_serial": 788984, "releases": { "0.1.0BETA": [ { "comment_text": "", "digests": { "md5": "0531b138fd12ae5b706a693485d9bf83", "sha256": "c979ecb46a92b657a5b36bdfcd238c5c186976e4c80a8752279d6de6e3169988" }, "downloads": -1, "filename": "discount-0.1.0BETA.tar.gz", "has_sig": false, "md5_digest": "0531b138fd12ae5b706a693485d9bf83", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11906, "upload_time": "2010-01-15T15:53:42", "url": "https://files.pythonhosted.org/packages/03/d0/3516277dcc1a5e7d48f61c052e6dc9ece89d97808d59156bacfe85199492/discount-0.1.0BETA.tar.gz" } ], "0.1.0STABLE": [ { "comment_text": "", "digests": { "md5": "09603181116aa3dbc7a8d6653bef4a23", "sha256": "4f240b77945901b8688b9f349be48637f7a8e8f83301f81efe2d8a4531cc3576" }, "downloads": -1, "filename": "discount-0.1.0STABLE.tar.gz", "has_sig": false, "md5_digest": "09603181116aa3dbc7a8d6653bef4a23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12656, "upload_time": "2010-01-29T18:07:49", "url": "https://files.pythonhosted.org/packages/b6/a8/3d6dbbf02e0f52ebfae80857edd8d8588bb044e1f087349986e1d9391ef5/discount-0.1.0STABLE.tar.gz" } ], "0.2.0ALPHA": [ { "comment_text": "", "digests": { "md5": "df589c82cc40cc9a4038d5f9d780b521", "sha256": "3adcc5ec621b4c878a22c59328a4660efdb9c4529e511fd97f2e2e565bc2f250" }, "downloads": -1, "filename": "discount-0.2.0ALPHA.tar.gz", "has_sig": false, "md5_digest": "df589c82cc40cc9a4038d5f9d780b521", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14515, "upload_time": "2010-02-12T17:19:27", "url": "https://files.pythonhosted.org/packages/c8/c3/76581363f5eb34b72272837ff6646d669d2e6c156998579d92ee06bf24a5/discount-0.2.0ALPHA.tar.gz" } ], "0.2.0BETA": [ { "comment_text": "", "digests": { "md5": "8b7cc749c7b3a954731b279a5485e2ac", "sha256": "674006b59f9d2b185637283d717708c39d5abee23ab4e534723552f5f4643c29" }, "downloads": -1, "filename": "discount-0.2.0BETA.tar.gz", "has_sig": false, "md5_digest": "8b7cc749c7b3a954731b279a5485e2ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14558, "upload_time": "2010-02-12T17:38:01", "url": "https://files.pythonhosted.org/packages/cd/8d/becb68d2d99b7f26d1c225f42ad6412aa325501db8275f5707967c65e5fd/discount-0.2.0BETA.tar.gz" } ], "0.2.1STABLE": [ { "comment_text": "", "digests": { "md5": "814696ede966ff67ee25371a6a1bf406", "sha256": "962e6d7567664ac59884775396916a0edfe8082ce1b9f1bfb4b742279855ff09" }, "downloads": -1, "filename": "discount-0.2.1STABLE.tar.gz", "has_sig": false, "md5_digest": "814696ede966ff67ee25371a6a1bf406", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14857, "upload_time": "2010-03-01T17:59:39", "url": "https://files.pythonhosted.org/packages/0b/52/4f6d91d4797c8ecc55aaaf48042686e893fb1987a94660f8d00138c319df/discount-0.2.1STABLE.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "814696ede966ff67ee25371a6a1bf406", "sha256": "962e6d7567664ac59884775396916a0edfe8082ce1b9f1bfb4b742279855ff09" }, "downloads": -1, "filename": "discount-0.2.1STABLE.tar.gz", "has_sig": false, "md5_digest": "814696ede966ff67ee25371a6a1bf406", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14857, "upload_time": "2010-03-01T17:59:39", "url": "https://files.pythonhosted.org/packages/0b/52/4f6d91d4797c8ecc55aaaf48042686e893fb1987a94660f8d00138c319df/discount-0.2.1STABLE.tar.gz" } ] }