[Bug]: whitespace-only inline elements are removed from cleaned_html, merging words in raw_markdown (prose, not only <pre>/<code>)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 83/100
Direzione di ricerca
Inizia in content_scraping_strategy.py, da remove_empty_elements_fast, e traccia come vengono gestiti il testo e i tails degli elementi rimossi. Riproduci il problema con l’input HTML grezzo /crawl fornito usando content_source="cleaned_html"; il lavoro è completato quando gli elementi inline composti solo da spazi bianchi non uniscono più le parole in raw_markdown, preservando il comportamento esistente per gli altri contenuti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
crawl4ai version
0.9.3 (Docker image, REST /crawl and /md)
Expected Behavior
Text whose words are split into inline elements keeps its word spacing in raw_markdown, as it does when the markdown is generated from the raw HTML.
Current Behavior
remove_empty_elements_fast (content_scraping_strategy.py) removes whitespace-only inline elements outside <pre>/<code>, and the whitespace inside them goes with them. With the default content_source="cleaned_html", raw_markdown then merges the words: Hi there becomes Hithere.
Real-world trigger: pages whose scripts split text into per-character or per-word spans for animation. Today https://example.com rewrites its paragraph into one <span> per character with each space in its own <span> </span>. Through /md or /crawl (default cleaned_html), the paragraph comes back as Thisdomainisforuseindocumentationexampleswithoutneedingpermission.. Text on the same page that is not split into spans keeps its spaces.
Is this reproducible?
Yes
Inputs Causing the Bug
POST /crawl
{
"urls": ["raw:<html><body><p><span>H</span><span>i</span><span> </span><span>t</span><span>h</span><span>e</span><span>r</span><span>e</span></p><p>plain text stays fine</p></body></html>"],
"crawler_config": {"type": "CrawlerRunConfig", "params": {"cache_mode": "bypass",
"markdown_generator": {"type": "DefaultMarkdownGenerator", "params": {"content_source": "cleaned_html"}}}}
}
Output
content_source |
raw_markdown |
|---|---|
cleaned_html (default) |
Hithere\nplain text stays fine |
raw_html |
Hi there\nplain text stays fine |
cleaned_html no longer contains the <span> </span>:
<p><span>H</span><span>i</span><span>t</span><span>h</span><span>e</span><span>r</span><span>e</span></p>
Root cause
In remove_empty_elements_fast, a childless element whose stripped text has fewer than word_count_threshold words is removed. A whitespace-only element has zero words, so it is always removed. The function preserves the removed element's .tail, but not its own .text, so the space disappears. #1181 hit the same thing inside code and was fixed (v0.7.8) by skipping elements inside <pre>/<code>. Prose split into inline elements has no such guard. #2110 reports the same family of failure in PruningContentFilter on the fit_markdown path.
Suggested fix
When removing an element whose text is whitespace-only, keep the whitespace: append a single space to the previous sibling's .tail (or to parent.text), as is already done for .tail. Alternatively, never remove whitespace-only inline phrasing elements (span, em, strong, b, i, …).
Workaround
DefaultMarkdownGenerator(content_source="raw_html") (via /crawl; /md cannot set it). On the pages we checked it keeps the same words and links as cleaned_html and restores the spacing. fit_html also keeps spacing, but it drops links and pruned content.
- Lingua principale
- Python
- Stelle
- 84.8k
- Fork
- 8.8k
- Merge medio
- 14h 10m
- PR unite (30g)
- 12
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di unclecode/crawl4ai
-
[Bug]: HTTP crawler puts proxy credentials into the URL unencodedForse di nuovo libera @omarbounawarapy l’ha presa 11 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
unclecode/crawl4ai#2326 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Same PDF gives different markdown on each run when batch_size > 1 (threads share current_page_number)Forse già presa @Kylinny l’ha presa 12 giorni fa. Aperta🐞 Bug 🩺 Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
unclecode/crawl4ai#2319 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Reusing BFSDeepCrawlStrategy leaks the previous crawl's max_pages budget into a fresh runForse di nuovo libera @nightcityblade l’ha presa 12 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
unclecode/crawl4ai#2309 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Docker server fails to boot after mcp 2.0.0 release — mcp_bridge uses the removed v1 low-level APIForse di nuovo libera @nightcityblade l’ha presa 53 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
unclecode/crawl4ai#2147 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Docker memory guard reads host RAM when no container limit is set — cgroup v2 "max" defeats get_container_memory_percentForse già presa @Battleplus l’ha presa 49 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
unclecode/crawl4ai#2123 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di unclecode/crawl4ai
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
gradio-app/gradio#13964 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 93/100
BSData/horus-heresy-3rd-edition#3232 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jbacalso24/mimry#123 ·
I maintainer di solito rispondono entro 1 giorno
-
p:3-mid pydanty:bug pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
pydantic/pydantic-ai#10153 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue priority: medium size: S testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
cubrid-lab/cubrid-cookbook-python#316 ·
I maintainer di solito rispondono entro 1 giorno