fix(filter): skip pruning nodes inside pre/code blocks (#2110) - #2191
Open
Battleplus wants to merge 1 commit into
Open
fix(filter): skip pruning nodes inside pre/code blocks (#2110)#2191Battleplus wants to merge 1 commit into
Battleplus wants to merge 1 commit into
Conversation
PruningContentFilter was decomposing whitespace-only spans inside <pre>/<code> elements (e.g., <span class=\"w\"> </span> in syntax highlighting), corrupting code that raw_markdown preserves. Add _is_in_code_block() guard mirroring the existing fix in content_scraping_strategy.remove_empty_elements_fast (v0.7.8, unclecode#1181). Closes unclecode#2110
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.
Summary
Fixes #2110 — PruningContentFilter was decomposing whitespace-only spans inside pre/code elements, corrupting code that raw_markdown preserves.
Root cause
_prune_tree() in PruningContentFilter has no guard for code blocks. It scores every node and decomposes those below threshold, including whitespace-significant spans inside pre/code. The equivalent function in content_scraping_strategy.remove_empty_elements_fast already has this guard since v0.7.8 (#1181).
Fix
Add _is_in_code_block() helper that walks .parents checking for pre or code ancestors. _prune_tree() returns early for these nodes, matching the existing guard in remove_empty_elements_fast.
Files changed