Skip to content

Commit 5acf36f

Browse files
nfebebackportbot[bot]
authored andcommitted
fix(theming): Correctly generate CSS for font themes
Fixes a regression from dropping the SCSS compiler that broke font themes like OpenDyslexic. The old code relied on the SCSS compiler to automatically correct the order of the CSS rules, ensuring the @font-face declaration was always valid. The server now correctly generates the `@font-face` rule at the top level of the stylesheet, fixing the previously invalid nested CSS. Introduced in : f1448fc Signed-off-by: nfebe <[email protected]>
1 parent 6fe42f9 commit 5acf36f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

apps/theming/lib/Controller/ThemingController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,17 @@ public function getThemeStylesheet(string $themeId, bool $plain = false, bool $w
401401
$css = ":root { $variables } " . $customCss;
402402
} else {
403403
// If not set, we'll rely on the body class
404-
$css = "[data-theme-$themeId] { $variables $customCss }";
404+
// We need to separate @-rules from normal selectors, as they can't be nested
405+
// This is a replacement for the SCSS compiler that did this automatically before f1448fcf0777db7d4254cb0a3ef94d63be9f7a24
406+
// We need a better way to handle this, but for now we just remove comments and split the at-rules
407+
// from the rest of the CSS.
408+
$customCssWithoutComments = preg_replace('!/\*.*?\*/!s', '', $customCss);
409+
$customCssWithoutComments = preg_replace('!//.*!', '', $customCssWithoutComments);
410+
preg_match_all('/(@[^{]+{(?:[^{}]*|(?R))*})/', $customCssWithoutComments, $atRules);
411+
$atRulesCss = implode('', $atRules[0]);
412+
$scopedCss = preg_replace('/(@[^{]+{(?:[^{}]*|(?R))*})/', '', $customCssWithoutComments);
413+
414+
$css = "$atRulesCss [data-theme-$themeId] { $variables $scopedCss }";
405415
}
406416

407417
try {

0 commit comments

Comments
 (0)