Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 13, 2024
1 parent a6dfa58 commit c2d238c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}

}


Expand All @@ -160,7 +160,7 @@

function isLightOrDark($hex) {
$hex = ltrim($hex, '#');

$r = hexdec(strlen($hex) == 6 ? substr($hex, 0, 2) : str_repeat(substr($hex, 0, 1), 2));
$g = hexdec(strlen($hex) == 6 ? substr($hex, 2, 2) : str_repeat(substr($hex, 1, 1), 2));
$b = hexdec(strlen($hex) == 6 ? substr($hex, 4, 2) : str_repeat(substr($hex, 2, 1), 2));
Expand All @@ -177,7 +177,7 @@ function updateStylesForLightBackground($xpath) {
if (preg_match('/background\s*:\s*([^;]+);?/i', $style, $matches)) {
$bgColor = trim($matches[1]);
if (preg_match('/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $bgColor) && isLightOrDark($bgColor) == 'light') {

if (!str_contains($style, 'color')) {
$style .= ' color: #202122;';
}
Expand Down Expand Up @@ -296,11 +296,11 @@ function fetchWikiContent($page, $lang = 'en') {
function convertWidthToMaxWidth($xpath) {
foreach ($xpath->query('//*[@style]') as $node) {
$style = $node->getAttribute('style');

$updatedStyle = preg_replace_callback('/\bwidth\s*:\s*[^;]+;?/i', function ($matches) {
return str_replace('width', 'max-width', $matches[0]);
}, $style);

$node->setAttribute('style', $updatedStyle);
}
}
Expand Down Expand Up @@ -346,9 +346,9 @@ function processWikiContent($page, $lang = 'en') {
wrapTablesInDiv($xpath, array('responsive-wiki-table'),$dom);
removeWidthFromFloatRightDivs($xpath);
convertWidthToMaxWidth($xpath);
removeSrcsetAttributes($xpath);
removeSrcsetAttributes($xpath);
updateStylesForLightBackground($xpath);


return $dom->saveHTML();
}
Expand Down

0 comments on commit c2d238c

Please sign in to comment.