mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Output: Fix internal hyperlinks being ignored when they point to a HTML file whose <body> element has an id. Fixes #1464086 [ePub to DOCX conversion: no internal hyperlinks](https://bugs.launchpad.net/calibre/+bug/1464086) [ePub to DOCX conversion: no internal hyperlinks](https://bugs.launchpad.net/calibre/+bug/1464086)
This commit is contained in:
parent
7d172200b3
commit
1fc2082c4a
@ -404,7 +404,7 @@ class Convert(object):
|
||||
self.svg_rasterizer(self.oeb, self.opts)
|
||||
|
||||
self.styles_manager = StylesManager(self.docx.namespace, self.log, self.mi.language)
|
||||
self.links_manager = LinksManager(self.docx.namespace, self.docx.document_relationships)
|
||||
self.links_manager = LinksManager(self.docx.namespace, self.docx.document_relationships, self.log)
|
||||
self.images_manager = ImagesManager(self.oeb, self.docx.document_relationships)
|
||||
self.lists_manager = ListsManager(self.docx)
|
||||
self.fonts_manager = FontsManager(self.docx.namespace, self.oeb, self.opts)
|
||||
@ -454,7 +454,7 @@ class Convert(object):
|
||||
self.current_lang = lang_for_tag(item.data) or self.styles_manager.document_lang
|
||||
for i, body in enumerate(XPath('//h:body')(item.data)):
|
||||
with self.blocks:
|
||||
body.set('id', body.get('id', None) or self.links_manager.top_anchor)
|
||||
self.links_manager.bookmark_for_anchor(self.links_manager.top_anchor, self.current_item, body)
|
||||
self.process_tag(body, stylizer, is_first_tag=i == 0)
|
||||
|
||||
def process_tag(self, html_tag, stylizer, is_first_tag=False, float_spec=None):
|
||||
|
@ -61,8 +61,9 @@ def sanitize_bookmark_name(base):
|
||||
|
||||
class LinksManager(object):
|
||||
|
||||
def __init__(self, namespace, document_relationships):
|
||||
def __init__(self, namespace, document_relationships, log):
|
||||
self.namespace = namespace
|
||||
self.log = log
|
||||
self.document_relationships = document_relationships
|
||||
self.top_anchor = type('')(uuid4().hex)
|
||||
self.anchor_map = {}
|
||||
@ -107,6 +108,8 @@ class LinksManager(object):
|
||||
else:
|
||||
bmark = self.anchor_map[(href, self.top_anchor)]
|
||||
return self.namespace.makeelement(parent, 'w:hyperlink', w_anchor=bmark, w_tooltip=tooltip or '')
|
||||
else:
|
||||
self.log.warn('Ignoring internal hyperlink with href (%s) pointing to unknown destination' % url)
|
||||
if purl.scheme in {'http', 'https', 'ftp'}:
|
||||
if url not in self.external_links:
|
||||
self.external_links[url] = self.document_relationships.add_relationship(url, self.namespace.names['LINKS'], target_mode='External')
|
||||
|
Loading…
x
Reference in New Issue
Block a user