From 427ae5cd88141dbf57df2d1305bf0eb9962287c6 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 21 Feb 2014 00:00:00 +0000 Subject: [PATCH] rewrite relative imgs with pyquery. --- blogtopoid/blogtopoid.py | 9 +++++++++ requirements.txt | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/blogtopoid/blogtopoid.py b/blogtopoid/blogtopoid.py index 8d3c2d8..bd8fcc4 100644 --- a/blogtopoid/blogtopoid.py +++ b/blogtopoid/blogtopoid.py @@ -24,6 +24,7 @@ import PyRSS2Gen import markdown2 from cssmin import cssmin from slugify import slugify +from PyQuery import PyQuery from docutils.core import publish_parts from jinja2 import Environment, FileSystemLoader from pygments.formatters.html import HtmlFormatter @@ -160,6 +161,14 @@ class Post(object): 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'] = ''.join([config.blogurl, + self.outputpath, + img.attrib['src']]) + self.body = d.html() elif self.extension == '.rst': rst = publish_parts( post_content, diff --git a/requirements.txt b/requirements.txt index f9d0acb..18106f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,9 @@ Jinja2==2.7.2 -Pygments==1.6 PyRSS2Gen==1.1 PyYAML==3.10 +Pygments==1.6 cssmin==0.2.0 docutils==0.11 markdown2==2.2.0 +pyquery==1.2.8 python-slugify==0.0.7