Skip to content

fix: respect preserve_tags/preserve_classes in _remove_unwanted_tags - #2181

Open
Battleplus wants to merge 2 commits into
unclecode:mainfrom
Battleplus:fix/2167-preserve-tags-clean
Open

fix: respect preserve_tags/preserve_classes in _remove_unwanted_tags#2181
Battleplus wants to merge 2 commits into
unclecode:mainfrom
Battleplus:fix/2167-preserve-tags-clean

Conversation

@Battleplus

@Battleplus Battleplus commented Aug 22, 2026

Copy link
Copy Markdown

What

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.

Why

Fixes #2125preserve_tags and preserve_classes were no-ops when the tag was also in excluded_tags, because _remove_unwanted_tags ran after the preserve check and decomposed everything unconditionally.

How

  • In _remove_unwanted_tags(), add an _is_preserved() guard before element.decompose()
  • Reuse the existing helper that checks both preserve_tags and preserve_classes
  • Replace the stale opposite-semantics test with regression assertions for both tag- and class-based preservation

Testing

  • python -m pytest tests/test_pruning_preserve_whitelist_1900.py -q — 21 passed
  • Verified preserve_tags=["nav"] keeps an otherwise excluded <nav>
  • Verified preserve_classes=["site-footer"] keeps an otherwise excluded <footer>
  • Verified non-preserved excluded tags remain removed

Battleplus and others added 2 commits August 22, 2026 09:44
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
Battleplus force-pushed the fix/2167-preserve-tags-clean branch from e2c00f3 to 5a91fad Compare August 22, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: preserve_tags/preserve_classes are a no-op for excluded tags (aside, nav, footer, header, form)

1 participant