Example #1
0
    def test_insert_base_relative(self):
        """Replace relative base href"""
        html_in = '<html><head><base href="products/"><body></body></html>'
        html_target = '<html><head><base href="http://localhost:8000/products/" />\
<body></body></html>'
        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #2
0
    def test_insert_base_nohead(self):
        """Test base insert when no head element is present"""
        html_in = "<html><body>Body</body></html>"
        html_target = '<html>\n\
<head><base href="http://localhost:8000/" /></head>\n\
<body>Body</body></html>'
        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #3
0
    def test_insert_base_commented(self):
        """Test weird case when base tag is commented in origin"""
        html_in = '<html><head><!-- <base href="http://example.com/"> --></head>\
<body>Body</body></html>'
        html_target = '<html><head><base href="http://example.com/" />\
<!-- <base href="http://example.com/"> --></head><body>Body</body></html>'
        html_out = insert_base_url(html_in, "http://example.com/")
        self.assertEqual(html_out, html_target)
Example #4
0
    def test_insert_base_relative(self):
        """Replace relative base href"""
        html_in = '<html><head><base href="products/"><body></body></html>'
        html_target = '<html><head><base href="http://localhost:8000/products/" />\
<body></body></html>'

        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #5
0
    def test_insert_base_addbase(self):
        """add base tag when not present"""
        html_in = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\
<body></body></html>'
        html_target = '<html><head><base href="http://localhost:8000/" />\
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\
<body></body></html>'
        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #6
0
    def test_insert_base_nohead(self):
        """Test base insert when no head element is present"""
        html_in = '<html><body>Body</body></html>'
        html_target = '<html>\n\
<head><base href="http://localhost:8000/" /></head>\n\
<body>Body</body></html>'

        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #7
0
def html4annotation(htmlpage, baseurl=None):
    """Convert the given html document for the annotation UI

    This adds tags, removes scripts and optionally adds a base url
    """
    htmlpage = add_tagids(htmlpage)
    cleaned_html = descriptify(htmlpage)
    if baseurl:
        cleaned_html = insert_base_url(cleaned_html, baseurl)
    return cleaned_html
Example #8
0
def html4annotation(htmlpage, baseurl=None):
    """Convert the given html document for the annotation UI

    This adds tags, removes scripts and optionally adds a base url
    """
    htmlpage = add_tagids(htmlpage)
    cleaned_html = descriptify(htmlpage)
    if baseurl:
        cleaned_html = insert_base_url(cleaned_html, baseurl)
    return cleaned_html
Example #9
0
    def test_insert_base_commented(self):
        """Test weird case when base tag is commented in origin"""
        html_in = '<html><head><!-- <base href="http://example.com/"> --></head>\
<body>Body</body></html>'

        html_target = '<html><head><base href="http://example.com/" />\
<!-- <base href="http://example.com/"> --></head><body>Body</body></html>'

        html_out = insert_base_url(html_in, "http://example.com/")
        self.assertEqual(html_out, html_target)
Example #10
0
    def test_insert_base_addbase(self):
        """add base tag when not present"""
        html_in = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\
<body></body></html>'

        html_target = '<html><head><base href="http://localhost:8000/" />\
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\
<body></body></html>'

        html_out = insert_base_url(html_in, "http://localhost:8000/")
        self.assertEqual(html_out, html_target)
Example #11
0
 def test_insert_base_noreplace(self):
     """base tag dont need to be replaced"""
     html_in = html_target = '<html><head><base href="http://localhost:8000/products/"><body></body></html>'
     html_out = insert_base_url(html_in, "http://localhost:8000/users/blog.html")
     self.assertEqual(html_out, html_target)
Example #12
0
def clean(html, url):
    return insert_base_url(descriptify(html, url), url)
Example #13
0
def clean(html, url):
    return insert_base_url(descriptify(html, url), url)
Example #14
0
 def test_insert_base_noreplace(self):
     """base tag dont need to be replaced"""
     html_in = html_target = '<html><head><base href="http://localhost:8000/products/"><body></body></html>'
     html_out = insert_base_url(html_in,
                                "http://localhost:8000/users/blog.html")
     self.assertEqual(html_out, html_target)