rewrite relative imgs with pyquery.

This commit is contained in:
chris 2014-02-21 00:00:00 +00:00 committed by Christoph Gebhardt
parent eb9a25f8e5
commit 427ae5cd88
2 changed files with 11 additions and 1 deletions

View File

@ -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,

View File

@ -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