def docx_hyperlinks_can_be_collapsed(): result = convert_document_element_to_html( documents.document(children=[ documents.hyperlink(href="http://example.com", children=[documents.Text("Hello ")]), documents.hyperlink(href="http://example.com", children=[documents.Text("world")]), ])) assert_equal('<a href="http://example.com">Hello world</a>', result.value)
def hyperlink_is_read_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( documents.hyperlink(anchor="start", children=[documents.run([])]), _read_and_get_document_xml_element(element) )
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( documents.hyperlink(anchor="start", children=[documents.run([])]), _read_and_get_document_xml_element(element) )
def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag(): result = convert_document_element_to_html( documents.hyperlink(anchor="start", children=[documents.Text("Hello")]), id_prefix="doc-42-", ) assert_equal('<a href="#doc-42-start">Hello</a>', result.value)
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)
def hyperlink_is_read_if_it_has_a_relationship_id(self): relationships = Relationships({"r42": Relationship(target="http://example.com")}) run_element = xml_element("w:r") element = xml_element("w:hyperlink", {"r:id": "r42"}, [run_element]) assert_equal( documents.hyperlink(href="http://example.com", children=[documents.run([])]), _read_and_get_document_xml_element(element, relationships=relationships), )
def hyperlink_is_read_if_it_has_a_relationship_id(self): relationships = Relationships( {"r42": Relationship(target="http://example.com")}) run_element = xml_element("w:r") element = xml_element("w:hyperlink", {"r:id": "r42"}, [run_element]) assert_equal( documents.hyperlink("http://example.com", [documents.run([])]), _read_and_get_document_xml_element(element, relationships=relationships))
def existing_fragment_is_replaced_when_anchor_is_set_on_external_link(self): relationships = Relationships([ _hyperlink_relationship("r42", "http://example.com/#previous"), ]) 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) )
def hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id_and_an_anchor(self): relationships = Relationships([ _hyperlink_relationship("r42", "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) )
def docx_hyperlink_with_href_is_converted_to_anchor_tag(): result = convert_document_element_to_html( documents.hyperlink(href="http://example.com", children=[documents.Text("Hello")]), ) assert_equal('<a href="http://example.com">Hello</a>', result.value)
def docx_hyperlink_is_converted_to_anchor_tag(): result = convert_document_element_to_html( documents.hyperlink(href="http://example.com", children=[documents.Text("Hello")]), ) assert_equal('<a href="http://example.com">Hello</a>', result.value)