Skip to content

Conversation

@mre
Copy link
Member

@mre mre commented Dec 15, 2025

In #1485 it was requested to extract URLs from CSS files and inline styles.

While lychee proper is generally becoming more conservative about the file types we support, the places where links can occur in CSS are pleasantly limited to url() directives (with the exception of inline URLs in font-face and @import rules, which we conveniently ignore for now).

As such, integrating CSS support into lychee can be done by means of a simple extractor utilizing a bunch of regular expressions. It's not quite as exhaustive as a proper CSS parser (such as Servo's rust-cssparser crate), but on the plus side, we don't need to add additional dependencies.

Fixes #1485

@mre mre requested a review from thomas-zahner December 15, 2025 23:01
In #1485 it was requested to extract URLs from CSS files and inline
styles.

While lychee proper is generally becoming more conservative about the
file types we support, the places where links can occur in CSS are
pleasantly limited to `url()` directives (with the exception of inline
URLs in `font-face` and `@import` rules, which we conveniently ignore
for now).

As such, integrating CSS support into lychee can be done by means of a
simple extractor utilizing a bunch of regular expressions. It's not
quite as exhaustive as a proper CSS parser (such as Servo's
rust-cssparser crate), but on the plus side, we don't need to add
additional dependencies.

Fixes #1485
@mre mre force-pushed the feat/css-url-extraction branch from 9b3f374 to e80be51 Compare December 15, 2025 23:13
@mre
Copy link
Member Author

mre commented Dec 15, 2025

I briefly considered adding SCSS/SASS file support as well, but decided against it. Mainly for the following reasons:

  • SCSS/SASS are source files, not final CSS, so the compiled output might differ
  • Variables make URLs dynamic: url($cdn-path + '/image.png'), which we can't validate

Besides, users can opt-in with --include "*.scss" if needed.

@mre mre added the triage label Dec 16, 2025
Use top-level assert_eq for less code and better coverage
Copy link
Member

@thomas-zahner thomas-zahner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added 5409ff9. Do you agree with that? It's less code and yields better coverage

@mre
Copy link
Member Author

mre commented Dec 16, 2025

I've added 5409ff9. Do you agree with that? It's less code and yields better coverage

Absolutely! I forgot we had that. Much better, thanks.

@mre
Copy link
Member Author

mre commented Dec 16, 2025

AFAICT, the only open question is what we do with #1956 (comment).

@thomas-zahner
Copy link
Member

I see no problems, so we're good to merge

@mre mre merged commit 8d51c60 into master Dec 16, 2025
7 checks passed
@mre mre deleted the feat/css-url-extraction branch December 16, 2025 16:36
@mre
Copy link
Member Author

mre commented Dec 16, 2025

Thanks for the swift review.

@mre mre mentioned this pull request Dec 16, 2025
@mre mre mentioned this pull request Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to check url inside <style> tag and css file

2 participants