Example #1
0
 def get_xhtml(self, element=True):
     xhtml = ET.XML(markdown_to_xhtml(self.text))
     if self.font:
         span = ET.Element('span')
         span.set('style', 'font-family: ' + self.font + ';')
         span.append(xhtml)
         xhtml = span
     if element:
         return xhtml
     return ET.tostring(xhtml)
Example #2
0
    def _text2html(self, text):
        """
        Convert text to html.
        """
        html = self._replace(TEXT2HTML, text.strip())
        html = '<div>\n' + html + '\n</div>'

        try:
            # noinspection PyUnresolvedReferences
            return ET.XML(html)
        except (ParseError, SyntaxError) as e:
            logger.error('Could not parse html: %s', e)
            return None
Example #3
0
    def set_body(self, html):
        """
        Set the contents of the HTML body.

        Arguments:
            html -- Either a string or XML object. If the top level
                    element is not <body> with a namespace of
                    'http://www.w3.org/1999/xhtml', it will be wrapped.
        """
        if isinstance(html, str):
            html = ET.XML(html)
        if html.tag != '{http://www.w3.org/1999/xhtml}body':
            body = ET.Element('{http://www.w3.org/1999/xhtml}body')
            body.append(html)
            self.xml.append(body)
        else:
            self.xml.append(html)