From 4d8b8188a4c8a24a18695f2f4fe239321a9eb331 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 21 Feb 2014 00:00:00 +0000 Subject: [PATCH] de-complexify post.render() --- blogtopoid/blogtopoid.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/blogtopoid/blogtopoid.py b/blogtopoid/blogtopoid.py index af51f33..1e64345 100644 --- a/blogtopoid/blogtopoid.py +++ b/blogtopoid/blogtopoid.py @@ -157,18 +157,7 @@ class Post(object): # actually render post add_style = '' if self.extension == '.md': - self.body = markdown2.markdown( - post_content, - extras=config.mdextras, - ) - # rewrite relative img-srcs to full paths. - d = PyQuery(self.body) - for img in d.find('img'): - if not '/' in img.attrib['src']: - img.attrib['src'] = '{}{}/{}'.format(config.blogurl, - self.outputpath, - img.attrib['src']) - self.body = d.html() + self.render_md5(post_content) elif self.extension == '.rst': rst = publish_parts( post_content, @@ -187,6 +176,21 @@ class Post(object): add_style=add_style, ) + def render_md5(self, post_content): + config = Config() + self.body = markdown2.markdown( + post_content, + extras=config.mdextras, + ) + # rewrite relative img-srcs to full paths. + d = PyQuery(self.body) + for img in d.find('img'): + if not '/' in img.attrib['src']: + img.attrib['src'] = '{}{}/{}'.format(config.blogurl, + self.outputpath, + img.attrib['src']) + self.body = d.html() + class Page(Post): """ all info about a blog page.