compat(css): unset font-family for body when set to serif or sans-serif, closes #3334 (#3363)

This commit is contained in:
Huang Xin
2026-02-24 22:18:12 +08:00
committed by GitHub
parent 128b238bcb
commit 79ba9b3818
+15
View File
@@ -737,6 +737,21 @@ export const transformStylesheet = (css: string, vw: number, vh: number, vertica
return selector + block;
});
// unset font-family for body when set to serif or sans-serif
css = css.replace(ruleRegex, (_, selector, block) => {
if (/\bbody\b/i.test(selector)) {
const hasSerifFont = /font-family\s*:\s*serif\s*[;$]/.test(block);
const hasSansSerifFont = /font-family\s*:\s*sans-serif\s*[;$]/.test(block);
if (hasSerifFont) {
block = block.replace(/font-family\s*:\s*serif\s*([;$])/gi, 'font-family: unset$1');
}
if (hasSansSerifFont) {
block = block.replace(/font-family\s*:\s*sans-serif\s*([;$])/gi, 'font-family: unset$1');
}
}
return selector + block;
});
// replace absolute font sizes with rem units
// replace vw and vh as they cause problems with layout
// replace hardcoded colors