fix: respect preserve_tags/preserve_classes in _remove_unwanted_tags - #2181
Open
Battleplus wants to merge 2 commits into
Open
fix: respect preserve_tags/preserve_classes in _remove_unwanted_tags#2181Battleplus wants to merge 2 commits into
Battleplus wants to merge 2 commits into
Conversation
Previously, _remove_unwanted_tags() decomposed all matching elements regardless of the preserve whitelist. Now it checks _is_preserved() before decomposing, so elements matching preserve_tags or preserve_classes are kept even if their tag is in excluded_tags. Fixes unclecode#2125 Signed-off-by: Battleplus <3559424769@qq.com>
Battleplus
force-pushed
the
fix/2167-preserve-tags-clean
branch
from
August 22, 2026 08:11
e2c00f3 to
5a91fad
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Previously,
_remove_unwanted_tags()decomposed all matching elements regardless of the preserve whitelist. Now it checks_is_preserved()before decomposing, so elements matchingpreserve_tagsorpreserve_classesare kept even if their tag is inexcluded_tags.Why
Fixes #2125 —
preserve_tagsandpreserve_classeswere no-ops when the tag was also inexcluded_tags, because_remove_unwanted_tagsran after the preserve check and decomposed everything unconditionally.How
_remove_unwanted_tags(), add an_is_preserved()guard beforeelement.decompose()preserve_tagsandpreserve_classesTesting
python -m pytest tests/test_pruning_preserve_whitelist_1900.py -q— 21 passedpreserve_tags=["nav"]keeps an otherwise excluded<nav>preserve_classes=["site-footer"]keeps an otherwise excluded<footer>