From 7e4c20b52de2904e3fcdc760617c75d470f93c45 Mon Sep 17 00:00:00 2001 From: Ahmad Altaher Alfayad Date: Mon, 31 Jul 2023 10:04:48 -0400 Subject: [PATCH] Add transparent background as condition for inheritance --- src/Rule/BaseRule.php | 21 +++++++++++---------- src/Rule/CssTextHasContrast.php | 4 ++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Rule/BaseRule.php b/src/Rule/BaseRule.php index 36765cd..0571165 100644 --- a/src/Rule/BaseRule.php +++ b/src/Rule/BaseRule.php @@ -130,16 +130,17 @@ public function getStyle($element) { $style = $this->walkUpTreeForInheritance($element, $style); } - if($element->hasAttribute('style')) { - $inline_styles = explode(';', $element->getAttribute('style')); - foreach($inline_styles as $inline_style) { - $s = explode(':', $inline_style); + // if($element->hasAttribute('style')) { + // $inline_styles = explode(';', $element->getAttribute('style')); + // foreach($inline_styles as $inline_style) { + // $s = explode(':', $inline_style); + + // if(isset($s[1])){ // Edit: Make sure the style attribute doesn't have a trailing ; + // $style[trim($s[0])] = trim(strtolower($s[1])); + // } + // } + // } - if(isset($s[1])){ // Edit: Make sure the style attribute doesn't have a trailing ; - $style[trim($s[0])] = trim(strtolower($s[1])); - } - } - } if($element->tagName === "strong"){ $style['font-weight'] = "bold"; } @@ -201,7 +202,7 @@ private function walkUpTreeForInheritance($element, $style) { $style[$k] = $v; } - if((!isset($style['background-color'])) || strtolower($style['background-color']) == strtolower("#FFFFFF")){ + if((!isset($style['background-color'])) || strtolower($style['background-color']) == strtolower("#FFFFFF") || strtolower($style['background-color']) == strtolower("transparent")){ if($k == 'background-color'){ $style['background-color'] = $v; } diff --git a/src/Rule/CssTextHasContrast.php b/src/Rule/CssTextHasContrast.php index 894e03d..b281182 100644 --- a/src/Rule/CssTextHasContrast.php +++ b/src/Rule/CssTextHasContrast.php @@ -189,6 +189,10 @@ public function check() $style = $this->getStyle($element); } + if(strtolower($style['background-color']) == strtolower("transparent")) { + $style['background-color'] = $default_background; + } + // If the parent element doesn't have a text color, but one of the children does // then we won't assume the parent is using the LMS default if (!isset($style['color']) && $this->childrenHaveTextColor($element)) {