Skip to content

Commit

Permalink
Fix slevomat link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Nov 2, 2023
1 parent 215c44d commit 6c4b648
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tools/inherited-rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

$rules = $ruleset->getElementsByTagName('rule');

$slevomatReadme = file_get_contents('https://github.com/slevomat/coding-standard/blob/master/README.md');
$slevomatReadme = file_get_contents('https://raw.githubusercontent.com/slevomat/coding-standard/master/README.md');

function makeRefLink( string $ref ) : string {
global $slevomatReadme;
Expand All @@ -19,14 +19,9 @@ function makeRefLink( string $ref ) : string {
}

if( $parts[0] === 'SlevomatCodingStandard' ) {
$anchor = strtolower($ref);
$anchor = preg_replace('/\W/', '', $anchor);
if( strpos($slevomatReadme, "#$anchor-\"") ) {
return "[{$ref}](https://github.com/slevomat/coding-standard/blob/master/README.md#{$anchor}-)";
}

if( strpos($slevomatReadme, "#$anchor\"") ) {
return "[{$ref}](https://github.com/slevomat/coding-standard/blob/master/README.md#{$anchor})";
preg_match('/\['.preg_quote($ref).'\]\(([^)]+)\)/im', $slevomatReadme, $matches);
if($matches) {
return "[{$ref}](https://github.com/slevomat/coding-standard/blob/master/{$matches[1]})";
}
}

Expand All @@ -37,4 +32,4 @@ function makeRefLink( string $ref ) : string {
foreach( $rules as $rule ) {
echo '- ' . makeRefLink($rule->attributes->getNamedItem('ref')->nodeValue);
echo "\n";
}
}

0 comments on commit 6c4b648

Please sign in to comment.