def handle_entry(self, time, data): self.out.timestamp(time) if creole: emitter = creole.HtmlEmitter( creole.Parser(from_utf8(data)).parse(), self.out.new_id) data = emitter.emit() headers = emitter.headers else: data, headers = escape(data), [] self.out.newstate('entry', '', '', data) for level, text, targetid in headers: self.out.toc_entry(level, text, targetid)
def to_html(cls, kb_entry): def custom_link_emit(node): if node.children: text = html_emitter.emit_children(node) else: text = None return cls.convert_link(kb_entry, node.content, text) def custom_image_emit(node): target = cls.convert_attach(kb_entry, node.content) text = html_emitter.get_text(node) return u'<img src="%s" alt="%s" />' % (html_emitter.attr_escape( target), html_emitter.attr_escape(text)) parser = creole.Parser(unicode(kb_entry.body)) html_emitter = creole.HtmlEmitter(parser.parse(), macros=cls.get_macro_wrapper()) html_emitter.link_emit = custom_link_emit html_emitter.image_emit = custom_image_emit return html_emitter.emit()
def __call__(self, request, text): document = creole.Parser(text).parse() return creole.HtmlEmitter(document).emit().encode('utf-8', 'ignore')