Ejemplo n.º 1
0
 def test_get_hyperlinks(self):
     page_data = '''
     <div>
     <a href="/test/test1">test1</a>
     <a href="/test/test2">test2</a>
     </div>
     <table>
     <tr>
         <td><a href="/test/test3">test3</td>
         <td><a href="/test/test4">test4</td>
         <td><a href="http://www.test.com">test.com</td>
     </tr>
     </table>
     '''
     r = wikidata.get_hyperlinks(page_data)
     expect_links = [("test1","/test/test1"),
                     ("test2","/test/test2"),
                     ("test3","/test/test3"),
                     ("test4","/test/test4"),
                     ("test.com","http://www.test.com")]
     self.assertEqual(expect_links, r)
     r_hrefs_only = wikidata.get_hyperlinks(page_data, is_required_href_only=True)
     expected_links = ["/test/test1",
                     "/test/test2",
                     "/test/test3",
                     "/test/test4",
                     "http://www.test.com"]
     self.assertEqual(expected_links, r_hrefs_only)
Ejemplo n.º 2
0
 def get(self, path):
     if path.find("/") != 0:
         path = "/" + path
     if self.wiki_data.has_page(path):
         original_data = self.wiki_data.get_rendered_page(path)
         page_data = markdown.markdown(original_data)
         name_href_pairs = wikidata.get_hyperlinks(page_data)
         self.render("wikipage.html", pagePath=path[1:len(path)], pageData=page_data, link_pairs=name_href_pairs)
     else:
         self.redirect('/edit%s' % path)