Skip to content

fix(filter): respect preserve_tags in excluded_tags removal (#2125) - #2193

Open
Battleplus wants to merge 1 commit into
unclecode:mainfrom
Battleplus:fix/2125-preserve-tags-excluded
Open

fix(filter): respect preserve_tags in excluded_tags removal (#2125)#2193
Battleplus wants to merge 1 commit into
unclecode:mainfrom
Battleplus:fix/2125-preserve-tags-excluded

Conversation

@Battleplus

Copy link
Copy Markdown

Summary

Fixes #2125 — PruningContentFilter(preserve_tags=["aside"]) was silently ignored because _remove_unwanted_tags decomposes all excluded tags (nav, footer, header, aside, ...) before _prune_tree runs.

Root cause

_remove_unwanted_tags() decomposes every element in self.excluded_tags unconditionally. _prune_tree() respects preserve_tags via _is_preserved(), but the elements are already gone.

Fix

Add preserve_tags check in _remove_unwanted_tags to skip elements whose tag is in the preserve whitelist.

Files changed

  • crawl4ai/content_filter_strategy.py (+6/-1)

…e#2125)

_prune_tree already respects preserve_tags via _is_preserved(), but
_remove_unwanted_tags runs first and decomposes all excluded tags
(nav, footer, header, aside, ...) unconditionally. So
PruningContentFilter(preserve_tags=["aside"]) was silently ignored.

Add preserve_tags check in _remove_unwanted_tags to skip elements
whose tag is in the preserve whitelist.

Closes unclecode#2125
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