Skip to content

Commit 02eb875

Browse files
Merge pull request #53921 from nextcloud/backport/53857/stable31
[stable31] fix(theming): Correctly generate CSS for font themes
2 parents 3771f1c + 5acf36f commit 02eb875

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)