コード例 #1
0
def validate_html(html, version):
    """
    Validates HTML, and, if tag_validator is not None, also validates its
    contained tags.

    Might raise:
        HtmlCommentError
        InvalidHtmlTagError
        NestedHtmlTagError
        UnsupportedHtmlTag
    Use try/except in models clean method.
    """
    tags = extract_active_tags(html)
    for tag in tags:
        tag_is_allowed(tag, version)
コード例 #2
0
 def test_extract_tags(self, html_file, html_file_tags):
     assert extract_active_tags(html_file) == html_file_tags
コード例 #3
0
 def test_closing_unopened_tag(self):
     with pytest.raises(InvalidHtmlTagError):
         _ = extract_active_tags("><p>My paragraph")
コード例 #4
0
 def test_unopened_comment(self):
     with pytest.raises(HtmlCommentError):
         _ = extract_active_tags("-->")
コード例 #5
0
 def test_unclosed_comment(self):
     with pytest.raises(HtmlCommentError):
         _ = extract_active_tags("<!-- <title>Fail</title>")
コード例 #6
0
 def test_unclosed_tag(self):
     with pytest.raises(InvalidHtmlTagError):
         _ = extract_active_tags("<html")
コード例 #7
0
 def test_nested_tag(self):
     with pytest.raises(NestedHtmlTagError):
         _ = extract_active_tags("<<html>")