moviewyrm/bookwyrm/tests/validate_html.py

26 lines
707 B
Python
Raw Normal View History

2021-10-01 05:22:20 +00:00
""" html validation on rendered templates """
from tidylib import tidy_document
2021-10-01 05:23:29 +00:00
2021-10-01 05:22:20 +00:00
def validate_html(html):
2021-10-01 05:23:29 +00:00
"""run tidy on html"""
2021-10-01 05:22:20 +00:00
_, errors = tidy_document(
html.content,
options={
"drop-empty-elements": False,
"warn-proprietary-attributes": False,
},
)
# idk how else to filter out these unescape amp errs
errors = "\n".join(
e
for e in errors.split("\n")
if "&book" not in e
and "&type" not in e
and "id and name attribute" not in e
and "illegal characters found in URI" not in e
and "escaping malformed URI reference" not in e
2021-10-01 05:22:20 +00:00
)
if errors:
raise Exception(errors)