From f772284b08698a47430549f18abc6e004ac06fb6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 30 May 2017 11:10:05 +0100 Subject: Read target frame on hyperlinks --- mammoth/docx/body_xml.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'mammoth/docx') diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 49ff431..3e3e027 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -297,15 +297,24 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f def hyperlink(element): relationship_id = element.attributes.get("r:id") anchor = element.attributes.get("w:anchor") + target_frame = element.attributes.get("w:tgtFrame") children_result = _read_xml_elements(element.children) + + def create(**kwargs): + return children_result.map(lambda children: documents.hyperlink( + children=children, + target_frame=target_frame, + **kwargs + )) + if relationship_id is not None: href = relationships[relationship_id].target if anchor is not None: href = replace_fragment(href, anchor) - return children_result.map(lambda children: documents.hyperlink(href=href, children=children)) + return create(href=href) elif anchor is not None: - return children_result.map(lambda children: documents.hyperlink(anchor=anchor, children=children)) + return create(anchor=anchor) else: return children_result -- cgit v1.2.3