from markdown import markdown import html from normalutils.choices.htmlchoices import HtmlContentType def content_to_html(content: str, content_type=HtmlContentType.TEXT_MARKDOWN, title=None): if content_type == HtmlContentType.TEXT_MARKDOWN: content = markdown(content) return content elif content_type == HtmlContentType.TEXT_PLAIN: content = html.escape(content) content = content.split('\n') ret = '' for sentence in content: ret += ''.join(["

", sentence, "

\n"]) # add title if title is not None: title = html.escape(title) return ''.join(['

', title, '

\n', ret]) return ret