class EmbeddedContent(Template): def _generate(self, article, style=None, extra_css=None): content = article.content if article.content else "" summary = article.summary if article.summary else "" text = content if len(content) > len(summary) else summary head = HEAD(TITLE(article.title)) if style: head.append(STYLE(style, type="text/css")) if extra_css: head.append(STYLE(extra_css, type="text/css")) if isbytestring(text): text = text.decode("utf-8", "replace") elements = html.fragments_fromstring(text) self.root = HTML(head, BODY(H2(article.title), DIV())) div = self.root.find("body").find("div") if elements and isinstance(elements[0], unicode): div.text = elements[0] elements = list(elements)[1:] for elem in elements: if hasattr(elem, "getparent"): elem.getparent().remove(elem) else: elem = SPAN(elem) div.append(elem)
class EmbeddedContent(Template): def _generate(self, article, style=None, extra_css=None): content = article.content if article.content else '' summary = article.summary if article.summary else '' text = content if len(content) > len(summary) else summary head = HEAD(TITLE(article.title)) if style: head.append(STYLE(style, type='text/css')) if extra_css: head.append(STYLE(extra_css, type='text/css')) if isbytestring(text): text = text.decode('utf-8', 'replace') elements = html.fragments_fromstring(text) self.root = HTML(head, BODY(H2(article.title), DIV())) div = self.root.find('body').find('div') if elements and isinstance(elements[0], unicode_type): div.text = elements[0] elements = list(elements)[1:] for elem in elements: if hasattr(elem, 'getparent'): elem.getparent().remove(elem) else: elem = SPAN(elem) div.append(elem)