ext/markdown.py
author Christophe de Vienne <christophe@unlish.com>
Thu, 08 Jan 2015 22:11:06 +0100
changeset 10491 c67bcee93248
parent 10012 8c2c6fdd8d56
permissions -rw-r--r--
[doc] Restructure the documentation * Create a new index file * Move the sphinx configuration files do the documentation root * Move book/README to dev/documenting.rst * Move book/mode_plan.py to tools/ * Move book/en/images to images * Move book/en/* to book/ * Move changelogs to changes/* * Adapt the Makefile * Add a title to the javascript api index Related to #4832808

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