ext/markdown.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Wed, 16 Mar 2016 10:06:18 +0100
changeset 11213 5c4c0b96c522
parent 10012 8c2c6fdd8d56
permissions -rw-r--r--
[pkg] Use Twisted < 16.0.0 We have some test failures with 16.0.0, such as: - test_put_content (unittest_server.ETwistHTTPTC) - test_base_url (unittest_httptest.TwistedCWAnonTC) (grafted from 10c12f31d0fe38c2e8814176fc42bf2ea210efdf)

from __future__ import absolute_import
import markdown

import logging

log = logging.getLogger(__name__)


def markdown_publish(context, data):
    """publish a string formatted as MarkDown Text to HTML

    :type context: a cubicweb application object

    :type data: str
    :param data: some MarkDown text

    :rtype: unicode
    :return:
      the data formatted as HTML or the original data if an error occurred
    """
    md = markdown.Markdown()
    try:
        return md.convert(data)
    except:
        import traceback; traceback.print_exc()
        log.exception("Error while converting Markdown to HTML")
        return data