Skip to content

Commit

Permalink
* fix bug
Browse files Browse the repository at this point in the history
*    一口老血。。。
  • Loading branch information
YaoZeyuan committed Dec 14, 2015
1 parent 1bca50a commit d73b5bf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/tools/create_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ def __init__(self, image_container):
def fix_image(self, content):
content = Match.fix_html(content)
for img in re.findall(r'<img[^>]*', content):
# fix img
if img[-1] == '/':
img = img[:-1]
img += '>'

src = re.search(r'(?<=src=").*?(?=")', img)
if not src:
new_image = img + '></img>'
new_image = img + '</img>'
content = content.replace(img, new_image)
continue
else:
src = src.group(0)
if src.replace(' ', '') == '':
new_image = img + '></img>'
new_image = img + '</img>'
content = content.replace(img, new_image)
continue
src_download = CreateHtml.fix_image_src(src)
if src_download:
filename = self.image_container.add(src_download)
else:
filename = ''
img += '>'
new_image = img.replace('"{}"'.format(src), '"../images/{}"'.format(filename))
new_image = new_image.replace('//zhstatic.zhihu.com/assets/zhihu/ztext/whitedot.jpg',
'../images/{}'.format(filename))
Expand Down

0 comments on commit d73b5bf

Please sign in to comment.