From 47eb18cd5635efa0319972673a5bfa90e93f7680 Mon Sep 17 00:00:00 2001 From: Battleplus <3559424769@qq.com> Date: Mon, 24 Aug 2026 13:04:41 +0800 Subject: [PATCH] fix(filter): skip pruning nodes inside pre/code blocks (#2110) PruningContentFilter was decomposing whitespace-only spans inside
/ elements (e.g., 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, #1181).
Closes #2110
---
crawl4ai/content_filter_strategy.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/crawl4ai/content_filter_strategy.py b/crawl4ai/content_filter_strategy.py
index ab99a793c..40405e77f 100644
--- a/crawl4ai/content_filter_strategy.py
+++ b/crawl4ai/content_filter_strategy.py
@@ -712,6 +712,11 @@ def _prune_tree(self, node):
if self._is_preserved(node):
return
+ # Skip pruning for nodes inside or — whitespace is significant there
+ # (matches the guard in content_scraping_strategy.remove_empty_elements_fast, fix for #1181)
+ if self._is_in_code_block(node):
+ return
+
text_len = len(node.get_text(strip=True))
tag_len = len(node.encode_contents().decode("utf-8"))
link_text_len = sum(