From b537a3713700b4fc40a23d0ca51b11846d562328 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 1 Aug 2021 17:20:33 +0100 Subject: Handle internal hyperlinks created with complex fields --- tests/docx/body_xml_tests.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 664b438..4cd54eb 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -418,7 +418,7 @@ class ComplexFieldTests(object): return self._is_hyperlinked_run(children=[]) @istest - def runs_in_a_complex_field_for_hyperlinks_are_read_as_hyperlinks(self): + def runs_in_a_complex_field_for_hyperlinks_without_switch_are_read_as_external_hyperlinks(self): element = xml_element("w:p", {}, [ self._BEGIN_COMPLEX_FIELD, self._HYPERLINK_INSTRTEXT, @@ -440,6 +440,31 @@ class ComplexFieldTests(object): is_empty_run, ))) + @istest + def runs_in_a_complex_field_for_hyperlinks_with_l_switch_are_read_as_internal_hyperlinks(self): + element = xml_element("w:p", {}, [ + self._BEGIN_COMPLEX_FIELD, + xml_element("w:instrText", {}, [ + xml_text(' HYPERLINK \\l "InternalLink"'), + ]), + self._SEPARATE_COMPLEX_FIELD, + _run_element_with_text("this is a hyperlink"), + self._END_COMPLEX_FIELD, + ]) + paragraph = _read_and_get_document_xml_element(element) + + assert_that(paragraph, is_paragraph(children=is_sequence( + is_empty_run, + self._is_empty_hyperlinked_run, + self._is_hyperlinked_run( + anchor="InternalLink", + children=is_sequence( + is_text("this is a hyperlink"), + ), + ), + is_empty_run, + ))) + @istest def runs_after_a_complex_field_for_hyperlinks_are_not_read_as_hyperlinks(self): element = xml_element("w:p", {}, [ -- cgit v1.2.3