def rendered_body(self): html = cache.get_rendered_body(self.title) if html is not None: return html html = super(WikiPage, self).rendered_body cache.set_rendered_body(self.title, html) return html
def rendered_body(self): final = cache.get_rendered_body(self.title) if final is not None: return final # body body_parts = [WikiPage.remove_metadata(self.body)] # incoming links if len(self.inlinks) > 0: lines = [u'# Incoming Links'] for rel, links in self.inlinks.items(): itemtype, rel = rel.split('/') humane_rel = schema.humane_property(itemtype, rel, True) lines.append(u'## %s' % humane_rel) lines += [u'* [[%s]]' % title for title in set(links)] body_parts.append(u'\n'.join(lines)) # related links related_links = self.related_links_by_score if len(related_links) > 0: lines = [u'# Suggested Pages'] lines += [u'* {{.score::%.2f}} [[%s]]' % (score, title) for title, score in related_links.items()[:10]] body_parts.append(u'\n'.join(lines)) # other posts if self.older_title or self.newer_title: lines = [u'# Other Posts'] if self.newer_title: lines.append(u'* {{.newer::newer}} [[%s]]' % self.newer_title) if self.older_title: lines.append(u'* {{.older::older}} [[%s]]' % self.older_title) body_parts.append(u'\n'.join(lines)) # render to html rendered = md.convert(u'\n'.join(body_parts)) # add table of contents final = TocGenerator(rendered).add_toc() # add class for embedded image final = WikiPage.re_img.sub(u'<p class="img-container"><img \\1/></p>', final) # sanitize if final: cleaner = Cleaner(safe_attrs_only=False) final = cleaner.clean_html(final) cache.set_rendered_body(self.title, final) return final
def rendered_body(self): value = cache.get_rendered_body(self.title) if value is None: value = super(WikiPage, self).rendered_body cache.set_rendered_body(self.title, value) return value