From 9ec50c21586ea0234c0cb7c4e27ce81db6985106 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 3 Feb 2021 14:17:50 +0100 Subject: [PATCH] Add StyleCompiler::convertToRtl() --- .../lib/system/style/StyleCompiler.class.php | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 366922e3c8..8c42a51c97 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -556,21 +556,35 @@ EOT; \file_put_contents($filename . '.css', $content); FileUtil::makeWritable($filename . '.css'); - // convert stylesheet to RTL - $content = StyleUtil::convertCSSToRTL($content); - - // force code boxes to be always LTR - $content .= "\n/* RTL fix for code boxes */\n"; - $content .= ".redactor-layer pre { direction: ltr; text-align: left; }\n"; - $content .= ".codeBoxCode { direction: ltr; } \n"; - $content .= ".codeBox .codeBoxCode { padding-left: 7ch; padding-right: 0; } \n"; - $content .= ".codeBox .codeBoxCode > code .codeBoxLine > a { margin-left: -7ch; margin-right: 0; text-align: right; } \n"; + $content = $this->convertToRtl($content); // write stylesheet for RTL \file_put_contents($filename . '-rtl.css', $content); FileUtil::makeWritable($filename . '-rtl.css'); } + /** + * Converts the given CSS into the RTL variant. + * + * This method differs from StyleUtil::convertCSSToRTL() in that it includes some fixes + * for elements that need to remain LTR. + * + * @see StyleUtil::convertCSSToRTL() + */ + private function convertToRtl(string $css): string + { + $css = StyleUtil::convertCSSToRTL($css); + + // force code boxes to be always LTR + $css .= "\n/* RTL fix for code boxes */\n"; + $css .= ".redactor-layer pre { direction: ltr; text-align: left; }\n"; + $css .= ".codeBoxCode { direction: ltr; } \n"; + $css .= ".codeBox .codeBoxCode { padding-left: 7ch; padding-right: 0; } \n"; + $css .= ".codeBox .codeBoxCode > code .codeBoxLine > a { margin-left: -7ch; margin-right: 0; text-align: right; } \n"; + + return $css; + } + /** * Returns the name of the CSS file for a specific style. * -- 2.20.1