ext/markdown.py
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 16 Jan 2015 14:30:55 +0100
changeset 10203 1443fe643a38
parent 10012 8c2c6fdd8d56
permissions -rw-r--r--
[server] change order of entities table modification vs entity creation/deletion In order to have a foreign key referencing the entities table, the insertion into entities must happen first, and the deletion must happen last. For the deletion case, this means we need to: 1. delete all relations (cascade) 2. delete the entities themselves 3. delete the corresponding lines from the entities table This means the _delete_info{,_multi} methods can't keep doing 1 and 3. Thankfully the "public" delete_info method appears to be unused, so drop it. Related to #4846892.

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