diff options
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/documents.py | 5 | ||||
| -rw-r--r-- | mammoth/docx/body_xml.py | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py index b440846..04e9d8e 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -41,6 +41,7 @@ class Text(Element): class Hyperlink(HasChildren): href = cobble.field() anchor = cobble.field() + target_frame = cobble.field() @cobble.data class Table(HasChildren): @@ -120,8 +121,8 @@ def tab(): image = Image -def hyperlink(children, href=None, anchor=None): - return Hyperlink(href=href, anchor=anchor, children=children) +def hyperlink(children, href=None, anchor=None, target_frame=None): + return Hyperlink(href=href, anchor=anchor, target_frame=target_frame, children=children) @cobble.data 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 |
