From 79ba9b381876893c700556d5f522db72cfa6b79d Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Tue, 24 Feb 2026 22:18:12 +0800 Subject: [PATCH] compat(css): unset font-family for body when set to serif or sans-serif, closes #3334 (#3363) --- apps/readest-app/src/utils/style.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/readest-app/src/utils/style.ts b/apps/readest-app/src/utils/style.ts index d9ea2758..786e5828 100644 --- a/apps/readest-app/src/utils/style.ts +++ b/apps/readest-app/src/utils/style.ts @@ -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