File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -1458,7 +1458,9 @@ function check()
14581458 $ style ['font-style ' ] = "normal " ;
14591459 }
14601460
1461- 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 ) {
1461+ if ($ element ->tagName === 'h1 ' || $ element ->tagName === 'h2 ' || $ element ->tagName === 'h3 ' || $ element ->tagName === 'h4 ' || $ element ->tagName === 'h5 ' || $ element ->tagName === 'h6 ' || $ this ->checkTextEqualsHeadingText ($ element )) {
1462+ continue ;
1463+ } elseif ($ font_size >= 18 ) {
14621464 if ($ luminosity >= 3 && !$ bold && !$ italic ) {
14631465 $ message = 'heading: background-color: ' . $ background . '; color: ' . $ style ["color " ] . '; font-style: ' . $ style ['font-style ' ] . '; font-weight: ' . $ style ['font-weight ' ] . '; ' ;
14641466 $ this ->addReport ($ element , $ message );
@@ -1472,6 +1474,32 @@ function check()
14721474 }
14731475 }
14741476 }
1477+
1478+ /**
1479+ * Returns true if the tag descends from a heading tag and
1480+ * contains the same text, or false otherwise.
1481+ * @param object $element A DOMElement object
1482+ */
1483+ function checkTextEqualsHeadingText ($ element )
1484+ {
1485+ $ headingAncestor = false ;
1486+ // Stop when we reach a heading or fail to find one.
1487+ for ($ i = 1 ; $ i <= 6 && !$ headingAncestor ; $ i ++) {
1488+ $ heading = "h " .$ i ;
1489+ $ headingAncestor = $ this ->getElementAncestor ($ element , $ heading );
1490+ }
1491+
1492+ // The current element is not descended from a heading.
1493+ if (!$ headingAncestor ) {
1494+ return false ;
1495+ }
1496+
1497+ if ($ element ->textContent === $ headingAncestor ->textContent ) {
1498+ return true ;
1499+ }
1500+
1501+ return false ;
1502+ }
14751503}
14761504
14771505/**
You can’t perform that action at this time.
0 commit comments