quizcomp.util.html
1import bs4 2 3def clean(raw_html: str, pretty: bool = False) -> str: 4 """ 5 Clean up and standardize the HTML. 6 If |pretty|, then the output will be indented properly, and extra space will be stripped (which may mess with some inline spacing). 7 |pretty| should only be used when being read by a human for visual inspection. 8 """ 9 10 raw_html = raw_html.strip() 11 if (len(raw_html) == 0): 12 return '' 13 14 document = bs4.BeautifulSoup(raw_html, 'html.parser') 15 16 if (pretty): 17 return document.prettify().strip() 18 19 return str(document).strip()
def
clean(raw_html: str, pretty: bool = False) -> str:
4def clean(raw_html: str, pretty: bool = False) -> str: 5 """ 6 Clean up and standardize the HTML. 7 If |pretty|, then the output will be indented properly, and extra space will be stripped (which may mess with some inline spacing). 8 |pretty| should only be used when being read by a human for visual inspection. 9 """ 10 11 raw_html = raw_html.strip() 12 if (len(raw_html) == 0): 13 return '' 14 15 document = bs4.BeautifulSoup(raw_html, 'html.parser') 16 17 if (pretty): 18 return document.prettify().strip() 19 20 return str(document).strip()
Clean up and standardize the HTML. If |pretty|, then the output will be indented properly, and extra space will be stripped (which may mess with some inline spacing). |pretty| should only be used when being read by a human for visual inspection.