cubicweb/ext/markdown.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Tue, 05 Mar 2019 13:52:52 +0100
branch3.26
changeset 12419 e034454af0d5
parent 11057 0b59724cb3f2
permissions -rw-r--r--
[py3] import configparser from six.moves instead of using a try/except Using six is better than the try/except because it clearly indicates compatibility code. Also, when using tools such as vermin which relies on AST, it helps getting rid of false compatibility errors.

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