[Bug]: PruningContentFilter cuts inline spans out of sentences it keeps (e.g. "renamed Tokyo (lit. '')")
Les mainteneurs répondent en général sous 1 jour
@siva23367 y travaille déjà.
Depuis le 19/10/2026.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 75/100
Piste de recherche
Start by reading PruningContentFilter and _prune_tree in crawl4ai/content_filter_strategy.py, then run the provided reproducer with nested spans inside kept paragraphs. Check how the default filter handles those spans compared with preserve_tags=["span"]. Done means the default output retains the text inside nested inline spans without dropping otherwise kept paragraph content.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
crawl4ai version
0.9.4 (reproduced). PruningContentFilter (crawl4ai/content_filter_strategy.py) is unchanged in v0.9.5 and on main (checked 2026-10-19).
Expected Behavior
When PruningContentFilter keeps a paragraph, the words inside that paragraph stay. A filter that removes a whole block is expected; a kept sentence with words missing from its middle is not.
Current Behavior
A <span> whose content is another element, such as a span around a link or a span around a span, is removed from a paragraph that is otherwise kept. Wikipedia marks up glosses and native-script names this way, so on https://en.wikipedia.org/wiki/Tokyo fit_markdown reads:
the city was renamed Tokyo (lit. '')
The source HTML is (<abbr>lit.</abbr> ... <span class="gloss-text"><a href="...">Eastern Capital</a></span> ...).
In the snippet below, plain spans, <strong>, <em> and links placed directly in the paragraph are kept; only the nested spans are lost.
My reading of the cause: _prune_tree scores every descendant element as if it were a block, and the score includes text density (text length over markup length) and link density. A short span whose only content is another element has little text against its markup, because the inner element's tags count as markup too. When the inner element is a link, the link density is also 1. Either way the span scores under the threshold and is removed.
Is this reproducible?
Yes
Inputs Causing the Bug
HTML with short nested inline spans inside a paragraph, for example https://en.wikipedia.org/wiki/Tokyo.
Steps to Reproduce
- Run the snippet below.
- Compare the
defaultoutput with the paragraphs inHTML.
Code snippets
import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig, CacheMode, DefaultMarkdownGenerator, PruningContentFilter
HTML = """<html><body><article>
<p>After the <a href="/wiki/Meiji_Restoration">Meiji Restoration</a> (1868), the imperial capital in <a href="/wiki/Kyoto">Kyoto</a> was moved to Edo, and the city was renamed Tokyo (<abbr title="literal translation">lit.</abbr> <span class="gloss-quot">'</span><span class="gloss-text"><a href="/wiki/Capital_of_Japan">Eastern Capital</a></span><span class="gloss-quot">'</span>). The city was greatly damaged by the 1923 earthquake and rebuilt in the following decades.</p>
<p>Tokyo (<span title="Japanese-language text"><span lang="ja">東京</span></span>) is the capital of Japan and one of the most populous cities in the world, with a population of about fourteen million.</p>
<p>The museum near the harbour holds <span>old maps</span> of the bay, <strong>ship models</strong> and <em>letters</em> written by the first merchants who settled on the northern quay.</p>
</article></body></html>"""
async def main():
async with AsyncWebCrawler() as crawler:
for name, flt in [("default", PruningContentFilter()), ("preserve_tags=['span']", PruningContentFilter(preserve_tags=["span"]))]:
config = CrawlerRunConfig(cache_mode=CacheMode.BYPASS, markdown_generator=DefaultMarkdownGenerator(content_filter=flt))
result = await crawler.arun("raw:" + HTML, config=config)
print(f"--- {name}")
print(result.markdown.fit_markdown)
asyncio.run(main())
Output on 0.9.4:
--- default
After the [Meiji Restoration](/wiki/Meiji_Restoration) (1868), the imperial capital in [Kyoto](/wiki/Kyoto) was moved to Edo, and the city was renamed Tokyo (lit. ''). The city was greatly damaged by the 1923 earthquake and rebuilt in the following decades.
Tokyo () is the capital of Japan and one of the most populous cities in the world, with a population of about fourteen million.
The museum near the harbour holds old maps of the bay, **ship models** and _letters_ written by the first merchants who settled on the northern quay.
*[lit.]: literal translation
--- preserve_tags=['span']
After the [Meiji Restoration](/wiki/Meiji_Restoration) (1868), the imperial capital in [Kyoto](/wiki/Kyoto) was moved to Edo, and the city was renamed Tokyo (lit. '[Eastern Capital](/wiki/Capital_of_Japan)'). The city was greatly damaged by the 1923 earthquake and rebuilt in the following decades.
Tokyo (東京) is the capital of Japan and one of the most populous cities in the world, with a population of about fourteen million.
The museum near the harbour holds old maps of the bay, **ship models** and _letters_ written by the first merchants who settled on the northern quay.
*[lit.]: literal translation
Workaround and suggestion
preserve_tags=["span"] fixes it: a preserved element is kept whole and not scored. On the Tokyo page it grows fit_markdown by about 2% (139,263 to 141,985 characters), so it does not let noticeably more noise through. Lowering the threshold, the workaround discussed in #582, applies to the whole page instead.
Since a filter that keeps a block should keep the block's words, a possible fix is to stop scoring inline (phrasing) elements on their own and let them follow their nearest block ancestor. Making span part of the default preserve_tags would cover the cases above with a smaller change.
#582 reported a similar symptom for <a> and <strong> and was closed after tuning the threshold. This report is narrower: the kept sentence itself is left with holes.
OS
Debian GNU/Linux 12 (bookworm), in the official unclecode/crawl4ai:0.9.4 Docker image
Python version
3.12.14
Error logs & Screenshots (if applicable)
None.
- Langage dominant
- Python
- Étoiles
- 87.2k
- Forks
- 9.1k
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 25
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de unclecode/crawl4ai
-
BUG: UserAgentGenerator.generate ignores browser_type and returns a random browser stackPeut-être pris @HhH666-ux l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: Hardened docker-compose (read_only) keeps full Chromium from starting: crashpad needs a writable ~/.configPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte🐞 Bug 📌 Root caused
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
unclecode/crawl4ai#2494 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
[Feature]: Crawl4aiDockerClient has no public option for the API token the 0.9 server requiresOuverte⚙ Done ✨ Enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
Les mainteneurs répondent en général sous 1 jour
-
⚙ Done 🐞 Bug 📌 Root caused
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: PDF images saved with save_images_locally=True come back with an empty src in result.mediaOuverte⚙ Done 🐞 Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
unclecode/crawl4ai#2469 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de unclecode/crawl4ai
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
-
Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
pandas-dev/pandas#72163 ·
Les mainteneurs répondent en général sous 2 jours
-
LightFM prepare_test_df ignores mapping values and silently mislabels evaluation pairsPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
recommenders-team/recommenders#2480 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
521xueweihan/HelloGitHub#4385 ·
-
🐛 bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
pdm-project/pdm#4012 ·
Les mainteneurs répondent en général sous 1 jour