def __call__(self, data, contenttype=None, arguments=None): """ Function called by the converter to process the conversion. TODO: Add support for different arguments """ text = decode_data(data, contenttype) content = normalize_split_text(text) # Be sure we have empty string in the base url self.base_url = '' # We create an element tree from the HTML content # The content is a list of string, line per line # We can concatenate all in one string html_str = '' html_str = html_str.join(content) html_tree = HTML(html_str) # We should have a root element, which will be converted as <page> # for the DOM Tree. It can be <html> or <div>. # NB : If <html> used, it will be converted back to <div> after # one roundtrip if html_tree.tag.name != 'html' and html_tree.tag.name != 'div': html_str = ''.join(['<div>', html_str, '</div>']) html_tree = HTML(html_str) # Start the conversion of the first element # Every child of each element will be recursively convert too element = self.do_children(html_tree) # Add Global element to our DOM Tree body = moin_page.body(children=element) root = moin_page.page(children=[body]) return root
def __call__(self, data, contenttype=None, arguments=None): """ Function called by the converter to process the conversion. TODO: Add support for different arguments """ self.no_dups_flash = NoDupsFlash() text = decode_data(data, contenttype) # data cleanup is not needed by html_out, but is needed by moinwiki_out; CKEditor adds unwanted \n\t while '\t\t' in text: text = text.replace('\t\t', '\t') text = text.replace('\r\n\t', '').replace('\n\t', '') content = normalize_split_text(text) # Be sure we have empty string in the base url self.base_url = '' # We create an element tree from the HTML content # The content is a list of string, line per line # We can concatenate all in one string html_str = u'\n'.join(content) try: html_tree = HTML(html_str) except AssertionError as reason: # we suspect user has created or uploaded malformed HTML, try to show input as preformatted code msg = _('Error: malformed HTML: {reason}.').format(reason=reason) msg = '<div class="error"><p><strong>%s</strong></p></div>' % msg html_str = ''.join( ['<html>', msg, '<pre>', html_str, '</pre></html>']) try: html_tree = HTML(html_str) except ValueError: msg = _( 'Error: malformed HTML. Try viewing source with Highlight or Modify links.' ) msg = '<div class="error"><p><strong>%s</strong></p></div>' % msg html_str = ''.join(['<html>', msg, '</html>']) html_tree = HTML(html_str) # We should have a root element, which will be converted as <page> # for the DOM Tree. # NB : If <html> used, it will be converted back to <div> after # one roundtrip if html_tree.tag.name != 'html': html_str = ''.join(['<div>', html_str, '</div>']) html_tree = HTML(html_str) # Start the conversion of the first element # Every child of each element will be recursively convert too element = self.do_children(html_tree) # Add Global element to our DOM Tree body = moin_page.body(children=element) root = moin_page.page(children=[body]) return root