[Bug]: whitespace-only inline elements are removed from cleaned_html, merging words in raw_markdown (prose, not only <pre>/<code>)
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #2329 @drakeo338 による — マージ済み
評価
調査の方向性
content_scraping_strategy.py の remove_empty_elements_fast から始め、削除された要素の text と tails がどのように処理されるかを追跡します。content_source="cleaned_html" を使用して、提供された /crawl の raw-HTML 入力で再現します。完了条件は、空白のみのインライン要素が raw_markdown 内で単語を結合しなくなり、その他のコンテンツについては既存の動作が維持されることです。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 85.4k
- フォーク
- 8.9k
- 平均マージ
- 5日 13時間
- マージ済み PR(30日)
- 28
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
unclecode/crawl4ai のほかの issue
-
🐞 Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: HTTP crawler puts proxy credentials into the URL unencoded再び着手できるかも @omarbounawarapy が 13 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン⚙ Done 🐞 Bug 🥸 - Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
unclecode/crawl4ai#2326 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Same PDF gives different markdown on each run when batch_size > 1 (threads share current_page_number)対応中かも @Kylinny が 14 日前に担当しました。 オープン⚙ Done 🐞 Bug 🥸 - Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
unclecode/crawl4ai#2319 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Reusing BFSDeepCrawlStrategy leaks the previous crawl's max_pages budget into a fresh run再び着手できるかも @nightcityblade が 15 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン⚙ Done 🐞 Bug 📌 Root caused 🥸 - Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
unclecode/crawl4ai#2309 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Docker memory guard reads host RAM when no container limit is set — cgroup v2 "max" defeats get_container_memory_percent対応中かも @Battleplus が 51 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
unclecode/crawl4ai#2123 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
unclecode/crawl4ai の issue をすべて見る
似ている issue
-
customer-reported question
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Azure/azure-sdk-for-python#49548 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
btclib-org/btclib-wallet#409 ·
メンテナーはふだん 1 日以内に返信
-
Phase 2 PSA Capability & Career Profile
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fastmachinelearning/hls4ml#1582 ·
メンテナーはふだん 3 日以内に返信
-
Sort modelsオープンenhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信