Skip to content

fix: preserve inline CSS background images - #2223

Open
itsafal wants to merge 4 commits into
unclecode:developfrom
REsimplifiInc:codex/upstream-css-background-images
Open

fix: preserve inline CSS background images#2223
itsafal wants to merge 4 commits into
unclecode:developfrom
REsimplifiInc:codex/upstream-css-background-images

Conversation

@itsafal

@itsafal itsafal commented Sep 1, 2026

Copy link
Copy Markdown

Summary

Related to #1691. Crawl4AI currently omits image URLs declared in inline CSS background and background-image properties from its normal media and Markdown outputs.

This PR takes a deliberately narrow approach: it handles inline style attributes and routes the discovered URLs through the existing <img> extraction pipeline. It does not add computed-style extraction, external stylesheet parsing, new configuration, or new media models.

  • Include extracted background images in media.images, cleaned_html, and Markdown.
  • Preserve relative URL handling and existing image exclusion behavior.
  • Skip data:, blob:, and javascript: URLs.
  • Deduplicate repeated background URLs, including carousel clones.
  • Use quote- and parenthesis-aware parsing for inline declarations.

This is intentionally smaller than the broader, previously closed CSS-background proposal in #1702, minimizing changes across the crawler pipeline while addressing the common inline-style case.

List of files changed and why

  • crawl4ai/content_scraping_strategy.py - Extract inline CSS background URLs and route them through normal image processing.
  • tests/test_css_background_images.py - Add regression coverage for extraction, Markdown, exclusions, URL handling, parser edge cases, and deduplication.

How Has This Been Tested?

  • uv run --with pytest --with nest_asyncio --with tabulate pytest -q tests/test_css_background_images.py tests/test_issue_1484_css_selector.py tests/test_issue_1043_mermaid_svg.py (34 passed)
  • git diff --check

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (not applicable; this is an inline extraction behavior fix)
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@itsafal
itsafal changed the base branch from main to develop September 1, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants