def parse2latex(self, md_text): from ist.utils.texlist2 import TexList reduce_tag = 'div' secured_markdown = self._replace_math(md_text) latex_secured = TexList.prepare_plain(secured_markdown) # apply markdown html_secured = markdown.markdown(latex_secured, extensions=[ 'markdown.extensions.sane_lists', 'markdown.extensions.nl2br', 'ist.formatters.extensions.md_links', 'ist.formatters.extensions.md_strike']) html_secured = TexList.finish_plain(html_secured) html = self._md_latex.finish(html_secured) try: return ET.fromstring(html) except Exception as e: return ET.fromstring('<' + reduce_tag + '>' + html + '</' + reduce_tag + '>')