From 85f99611c84cf0853200fb358f135160c063b690 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 18 May 2017 19:52:04 +0100 Subject: Add anchor on hyperlinks as fragment if present --- tests/docx/body_xml_tests.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index d112349..1277238 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -600,7 +600,7 @@ def _assert_children_are_converted_normally(tag_name): @istest class HyperlinkTests(object): @istest - def hyperlink_is_read_if_it_has_a_relationship_id(self): + def hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id(self): relationships = Relationships({ "r42": Relationship(target="http://example.com") }) @@ -612,7 +612,19 @@ class HyperlinkTests(object): ) @istest - def hyperlink_is_read_if_it_has_an_anchor_attribute(self): + def hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id_and_an_anchor(self): + relationships = Relationships({ + "r42": Relationship(target="http://example.com/") + }) + run_element = xml_element("w:r") + element = xml_element("w:hyperlink", {"r:id": "r42", "w:anchor": "fragment"}, [run_element]) + assert_equal( + documents.hyperlink(href="http://example.com/#fragment", children=[documents.run([])]), + _read_and_get_document_xml_element(element, relationships=relationships) + ) + + @istest + def hyperlink_is_read_as_internal_hyperlink_if_it_has_an_anchor_attribute(self): run_element = xml_element("w:r") element = xml_element("w:hyperlink", {"w:anchor": "start"}, [run_element]) assert_equal( -- cgit v1.2.3