From 422cbf55eb2b01a75016adab99b9ea3973800f77 Mon Sep 17 00:00:00 2001 From: AlanFCMV Date: Thu, 9 Sep 2021 15:51:07 -0400 Subject: [PATCH 1/2] Allow fully colored headers as text emphasis --- .../quail/common/accessibility_tests.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/quail/quail/common/accessibility_tests.php b/lib/quail/quail/common/accessibility_tests.php index 50447cdfe..5a3533813 100755 --- a/lib/quail/quail/common/accessibility_tests.php +++ b/lib/quail/quail/common/accessibility_tests.php @@ -1458,7 +1458,9 @@ function check() $style['font-style'] = "normal"; } - if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || $font_size >= 18 || $font_size >= 14 && $bold) { + if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || checkTextEqualsHeadingText($element)) { + continue; + } elseif ($font_size >= 18) { if ($luminosity >= 3 && !$bold && !$italic) { $message = 'heading: background-color: ' . $background . '; color:' . $style["color"] . '; font-style: ' . $style['font-style'] . '; font-weight: ' . $style['font-weight'] . '; '; $this->addReport($element, $message); @@ -1472,6 +1474,32 @@ function check() } } } + + /** + * Returns true if the tag descends from a heading tag and + * contains the same text, or false otherwise. + * @param object $element A DOMElement object + */ + function checkTextEqualsHeadingText($element) + { + $headingAncestor = false; + // Stop when we reach a heading or fail to find one. + for ($i = 1; $i <= 6 && !$headingAncestor; $i++) { + $heading = "h".$i; + $headingAncestor = $this->getElementAncestor($element, $heading); + } + + // The current element is not descended from a heading. + if (!$headingAncestor) { + return false; + } + + if ($element->textContent === $headingAncestor->textContent) { + return true; + } + + return false; + } } /** From 08c5670dc7044d71a995de9ca46a0adbc7439c80 Mon Sep 17 00:00:00 2001 From: AlanFCMV Date: Thu, 9 Sep 2021 16:05:18 -0400 Subject: [PATCH 2/2] Fix function call --- lib/quail/quail/common/accessibility_tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/quail/quail/common/accessibility_tests.php b/lib/quail/quail/common/accessibility_tests.php index 5a3533813..74dd817f5 100755 --- a/lib/quail/quail/common/accessibility_tests.php +++ b/lib/quail/quail/common/accessibility_tests.php @@ -1458,7 +1458,7 @@ function check() $style['font-style'] = "normal"; } - if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || checkTextEqualsHeadingText($element)) { + if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6' || $this->checkTextEqualsHeadingText($element)) { continue; } elseif ($font_size >= 18) { if ($luminosity >= 3 && !$bold && !$italic) {