diff --git a/tools/inherited-rules.php b/tools/inherited-rules.php index 4c0dd2f..3f606a5 100644 --- a/tools/inherited-rules.php +++ b/tools/inherited-rules.php @@ -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; @@ -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]})"; } } @@ -37,4 +32,4 @@ function makeRefLink( string $ref ) : string { foreach( $rules as $rule ) { echo '- ' . makeRefLink($rule->attributes->getNamedItem('ref')->nodeValue); echo "\n"; -} \ No newline at end of file +}