mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 15:30:00 -04:00
fix oversight in css rewriter
This commit is contained in:
parent
39d7529535
commit
635494f44f
1 changed files with 16 additions and 16 deletions
|
@ -9,32 +9,32 @@ export function unrewriteCss(css: string) {
|
|||
}
|
||||
|
||||
function handleCss(type: "rewrite" | "unrewrite", css: string, meta?: URLMeta) {
|
||||
// regex from vk6 (https://github.com/ading2210)
|
||||
const urlRegex = /url\(['"]?(.+?)['"]?\)/gm;
|
||||
const Atruleregex =
|
||||
/@import\s+(url\s*?\(.{0,9999}?\)|['"].{0,9999}?['"]|.{0,9999}?)($|\s|;)/gm;
|
||||
css = new String(css).toString();
|
||||
css = css.replace(urlRegex, (match, url) => {
|
||||
const encodedUrl =
|
||||
type === "rewrite"
|
||||
? rewriteUrl(url.trim(), meta)
|
||||
: unrewriteUrl(url.trim());
|
||||
type === "rewrite" ? rewriteUrl(url, meta) : unrewriteUrl(url);
|
||||
|
||||
return match.replace(url, encodedUrl);
|
||||
});
|
||||
css = css.replace(Atruleregex, (_, importStatement) => {
|
||||
return importStatement.replace(
|
||||
/^(url\(['"]?|['"]|)(.+?)(['"]|['"]?\)|)$/gm,
|
||||
(match, firstQuote, url, endQuote) => {
|
||||
if (firstQuote.startsWith("url")) {
|
||||
return match;
|
||||
}
|
||||
const encodedUrl =
|
||||
type === "rewrite"
|
||||
? rewriteUrl(url.trim(), meta)
|
||||
: unrewriteUrl(url.trim());
|
||||
css = css.replace(Atruleregex, (match, importStatement) => {
|
||||
return match.replace(
|
||||
importStatement,
|
||||
importStatement.replace(
|
||||
/^(url\(['"]?|['"]|)(.+?)(['"]|['"]?\)|)$/gm,
|
||||
(match, firstQuote, url, endQuote) => {
|
||||
if (firstQuote.startsWith("url")) {
|
||||
return match;
|
||||
}
|
||||
const encodedUrl =
|
||||
type === "rewrite" ? rewriteUrl(url, meta) : unrewriteUrl(url);
|
||||
|
||||
return `${firstQuote}${encodedUrl}${endQuote}`;
|
||||
}
|
||||
return `${firstQuote}${encodedUrl}${endQuote}`;
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue