diff options
| -rw-r--r-- | mammoth/conversion.py | 6 | ||||
| -rw-r--r-- | tests/conversion_tests.py | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index eb09ded..0fc3d58 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -149,8 +149,12 @@ class _DocumentConverter(documents.element_visitor(args=1)): else: href = "#{0}".format(self._html_id(hyperlink.anchor)) + attributes = {"href": href} + if hyperlink.target_frame is not None: + attributes["target"] = hyperlink.target_frame + nodes = self._visit_all(hyperlink.children, context) - return [html.collapsible_element("a", {"href": href}, nodes)] + return [html.collapsible_element("a", attributes, nodes)] def visit_bookmark(self, bookmark, context): diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index 9b81bf1..77b0a30 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -281,6 +281,18 @@ def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag(): @istest +def hyperlink_target_frame_is_used_as_anchor_target(): + result = convert_document_element_to_html( + documents.hyperlink( + anchor="start", + target_frame="_blank", + children=[documents.Text("Hello")], + ), + ) + assert_equal('<a href="#start" target="_blank">Hello</a>', result.value) + + +@istest def bookmarks_are_converted_to_anchors_with_ids(): result = convert_document_element_to_html( documents.bookmark(name="start"), |
