mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
HTMLZ Output: Fix bug with rewriting links.
This commit is contained in:
parent
33f0f6c648
commit
70bcc90bca
@ -62,24 +62,22 @@ class OEB2HTML(object):
|
|||||||
self.links[aid] = 'calibre_link-%s' % len(self.links.keys())
|
self.links[aid] = 'calibre_link-%s' % len(self.links.keys())
|
||||||
return self.links[aid]
|
return self.links[aid]
|
||||||
|
|
||||||
def rewrite_links(self, tag, attribs, page):
|
def rewrite_link(self, tag, attribs, page):
|
||||||
# Rewrite ids.
|
# Rewrite ids.
|
||||||
if 'id' in attribs:
|
if 'id' in attribs:
|
||||||
attribs['id'] = self.get_link_id(page.href, attribs['id'])
|
attribs['id'] = self.get_link_id(page.href, attribs['id'])
|
||||||
# Rewrite links.
|
# Rewrite links.
|
||||||
if tag == 'a':
|
if tag == 'a':
|
||||||
href = attribs['href']
|
href = page.abshref(attribs['href'])
|
||||||
href = page.abshref(href)
|
|
||||||
if self.url_is_relative(href):
|
if self.url_is_relative(href):
|
||||||
if '#' not in href:
|
id = ''
|
||||||
href += '#'
|
if '#' in href:
|
||||||
if href not in self.links:
|
href, n, id = href.partition('#')
|
||||||
self.links[href] = 'calibre_link-%s' % len(self.links.keys())
|
href = '#%s' % self.get_link_id(href, id)
|
||||||
href = '#%s' % self.links[href]
|
|
||||||
attribs['href'] = href
|
attribs['href'] = href
|
||||||
return attribs
|
return attribs
|
||||||
|
|
||||||
def rewrite_images(self, tag, attribs, page):
|
def rewrite_image(self, tag, attribs, page):
|
||||||
if tag == 'img':
|
if tag == 'img':
|
||||||
src = attribs.get('src', None)
|
src = attribs.get('src', None)
|
||||||
if src:
|
if src:
|
||||||
@ -131,6 +129,10 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
|
|||||||
tags = []
|
tags = []
|
||||||
tag = barename(elem.tag)
|
tag = barename(elem.tag)
|
||||||
attribs = elem.attrib
|
attribs = elem.attrib
|
||||||
|
|
||||||
|
attribs = self.rewrite_link(tag, attribs, page)
|
||||||
|
attribs = self.rewrite_image(tag, attribs, page)
|
||||||
|
|
||||||
if tag == 'body':
|
if tag == 'body':
|
||||||
tag = 'div'
|
tag = 'div'
|
||||||
attribs['id'] = self.get_link_id(page.href, '')
|
attribs['id'] = self.get_link_id(page.href, '')
|
||||||
@ -147,9 +149,6 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
|
|||||||
if 'style' in attribs:
|
if 'style' in attribs:
|
||||||
del attribs['style']
|
del attribs['style']
|
||||||
|
|
||||||
attribs = self.rewrite_links(tag, attribs, page)
|
|
||||||
attribs = self.rewrite_images(tag, attribs, page)
|
|
||||||
|
|
||||||
# Turn the rest of the attributes into a string we can write with the tag.
|
# Turn the rest of the attributes into a string we can write with the tag.
|
||||||
at = ''
|
at = ''
|
||||||
for k, v in attribs.items():
|
for k, v in attribs.items():
|
||||||
@ -219,6 +218,9 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
|||||||
tag = barename(elem.tag)
|
tag = barename(elem.tag)
|
||||||
attribs = elem.attrib
|
attribs = elem.attrib
|
||||||
|
|
||||||
|
attribs = self.rewrite_link(tag, attribs, page)
|
||||||
|
attribs = self.rewrite_image(tag, attribs, page)
|
||||||
|
|
||||||
style_a = '%s' % style
|
style_a = '%s' % style
|
||||||
if tag == 'body':
|
if tag == 'body':
|
||||||
tag = 'div'
|
tag = 'div'
|
||||||
@ -233,9 +235,6 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
|||||||
if 'style' in attribs:
|
if 'style' in attribs:
|
||||||
del attribs['style']
|
del attribs['style']
|
||||||
|
|
||||||
attribs = self.rewrite_links(tag, attribs, page)
|
|
||||||
attribs = self.rewrite_images(tag, attribs, page)
|
|
||||||
|
|
||||||
# Turn the rest of the attributes into a string we can write with the tag.
|
# Turn the rest of the attributes into a string we can write with the tag.
|
||||||
at = ''
|
at = ''
|
||||||
for k, v in attribs.items():
|
for k, v in attribs.items():
|
||||||
@ -312,6 +311,9 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
|
|||||||
tag = barename(elem.tag)
|
tag = barename(elem.tag)
|
||||||
attribs = elem.attrib
|
attribs = elem.attrib
|
||||||
|
|
||||||
|
attribs = self.rewrite_link(tag, attribs, page)
|
||||||
|
attribs = self.rewrite_image(tag, attribs, page)
|
||||||
|
|
||||||
if tag == 'body':
|
if tag == 'body':
|
||||||
tag = 'div'
|
tag = 'div'
|
||||||
attribs['id'] = self.get_link_id(page.href, '')
|
attribs['id'] = self.get_link_id(page.href, '')
|
||||||
@ -321,9 +323,6 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
|
|||||||
if 'style' in attribs:
|
if 'style' in attribs:
|
||||||
del attribs['style']
|
del attribs['style']
|
||||||
|
|
||||||
attribs = self.rewrite_links(tag, attribs, page)
|
|
||||||
attribs = self.rewrite_images(tag, attribs, page)
|
|
||||||
|
|
||||||
# Turn the rest of the attributes into a string we can write with the tag.
|
# Turn the rest of the attributes into a string we can write with the tag.
|
||||||
at = ''
|
at = ''
|
||||||
for k, v in attribs.items():
|
for k, v in attribs.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user