mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
Merge pull request #1 from YourAdIsHere/main
Add support for css @import rules
This commit is contained in:
commit
fb18c8af9f
1 changed files with 7 additions and 3 deletions
|
@ -1,7 +1,11 @@
|
|||
import { encodeUrl } from "./url"
|
||||
import { encodeUrl } from "./url";
|
||||
|
||||
export function rewriteCss(css: string, origin?: URL) {
|
||||
css = css.replace(/(?<=url\("?'?)[^"'][\S]*[^"'](?="?'?\);?)/g, (match) => encodeUrl(match, origin));
|
||||
|
||||
//painful regex simulator
|
||||
css = css.replace(/@import\s+(['"])?([^'"\);]+)\1?\s*(?:;|$)/g, (match, quote, url) => {
|
||||
return `@import ${quote || ""}${encodeUrl(url.trim(), origin)}${quote || ""};`;
|
||||
});
|
||||
return css;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue