Skip to content

Commit 9a8e74d

Browse files
authored
Merge pull request #53857 from nextcloud/fix/dyslexia-font-not-loading
fix(theming): Correctly generate CSS for font themes
2 parents 1a07c55 + 625c126 commit 9a8e74d

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

408418
try {

0 commit comments

Comments
 (0)