-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch
html_utils.clean_html
's cleaner
We switch from `lxml.html.clean.Cleaner` to `nh3.clean`. Doing so will allow us to remove the former (in a follow-up commit). Whilst `nh3.clean` says that it conforms to the HTML5 specification, it adds unnecessary `tbody` elements to `table` elements, which doesn't conform.[^1] However, we accept that it adds unnecessary `tbody` elements, modify the tests, and move on. Closes #4254 [^1]: https://html.spec.whatwg.org/multipage/tables.html#the-tbody-element
- Loading branch information
1 parent
1f84123
commit aaf227b
Showing
3 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from lxml.html.clean import Cleaner | ||
import nh3 | ||
|
||
|
||
def clean_html(html): | ||
cleaned = Cleaner(page_structure=False, style=True, kill_tags=["head"]).clean_html( | ||
html | ||
) | ||
""" | ||
Cleans the given HTML document/fragment with a whitelist-based cleaner, returning an | ||
HTML fragment that conforms to the HTML5 specification. | ||
""" | ||
cleaned = nh3.clean(html) | ||
return cleaned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters