def test_get_link_list(self): link1 = odf_create_link('http://example.com/', name='link1') link2 = odf_create_link('http://example.com/', name='link2') paragraph = self.paragraph paragraph.append(link1) paragraph.append(link2) element = self.body.get_links()[1] expected = ('<text:a xlink:href="http://example.com/" ' 'office:name="link2"/>') self.assertEqual(element.serialize(), expected)
def test_get_link_list_not_found(self): link1 = odf_create_link('http://example.com/', name='link1', title='title1') link2 = odf_create_link('http://example.com/', name='link2', title='title2') paragraph = self.paragraph paragraph.append(link1) paragraph.append(link2) # Not found element = self.body.get_links(name='link1', title='title2') self.assertEqual(element, [])
def test_get_link_list_href(self): link1 = odf_create_link('http://example.com/', name='link1', title='title1') link2 = odf_create_link('http://example.com/', name='link2', title='title2') paragraph = self.paragraph paragraph.append(link1) paragraph.append(link2) # url elements = self.body.get_links(url=ur'\.com') self.assertEqual(len(elements), 2)
def test_get_link_list_name_and_title(self): link1 = odf_create_link('http://example.com/', name='link1', title='title1') link2 = odf_create_link('http://example.com/', name='link2', title='title2') paragraph = self.paragraph paragraph.append(link1) paragraph.append(link2) # name and title element = self.body.get_links(name='link1', title='title1')[0] expected = ('<text:a xlink:href="http://example.com/" ' 'office:name="link1" office:title="title1"/>') self.assertEqual(element.serialize(), expected)
def test_get_link_list_href(self): link1 = odf_create_link('http://example.com/', name='link1', title='title1') link2 = odf_create_link('http://example.com/', name='link2', title='title2') paragraph = self.paragraph paragraph.append(link1) paragraph.append(link2) # url elements = self.body.get_links(url=r'\.com') self.assertEqual(len(elements), 2)
def convert_reference(node, context): refuri = node.get("refuri") text = node.astext() link = odf_create_link(refuri) link.set_text(text) context["top"].append_element(link)
def test_create_link2(self): link = odf_create_link('http://example.com/', name=u'link2', target_frame='_blank', style='style1', visited_style='style2') expected = ('<text:a xlink:href="http://example.com/" ' 'office:name="link2" office:target-frame-name="_blank" ' 'xlink:show="new" text:style-name="style1" ' 'text:visited-style-name="style2"/>') self.assertEqual(link.serialize(), expected)
def test_create_link2(self): link = odf_create_link('http://example.com/', name='link2', target_frame='_blank', style='style1', visited_style='style2') expected = ('<text:a xlink:href="http://example.com/" ' 'office:name="link2" office:target-frame-name="_blank" ' 'xlink:show="new" text:style-name="style1" ' 'text:visited-style-name="style2"/>') self.assertEqual(link.serialize(), expected)
def link(self, link, title, content): lnk = odf_create_link(link, text=content.get()[0].get_text(), title=unicode(title)) return ODFPartialTree.from_metrics_provider([lnk], self)
def autolink(self, link, is_email=False): text = link if is_email: link = 'mailto:%s' % link lnk = odf_create_link(link, text=unicode(text)) return ODFPartialTree.from_metrics_provider([lnk], self)
def test_create_link1(self): link = odf_create_link('http://example.com/') expected = '<text:a xlink:href="http://example.com/"/>' self.assertEqual(link.serialize(), expected)