cubicweb/ext/markdown.py
author Laurent Peuch <cortex@worlddomination.be>
Tue, 12 Mar 2019 11:40:59 +0100
changeset 12492 a7ffcaae7f4c
parent 11057 0b59724cb3f2
permissions -rw-r--r--
[doc/changelog] the removal of next_tabindex produce an error not in the changelog When one tried to migrate to 3.25, the error "class X initialization doesn't have a settabindex argument" can happen but the word "settabindex" is not present in the changelog which makes it hard to find to which modification this error is related.

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