From 6c4b648e9248dca1c5655f5e0ba148e0c41fd4aa Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Thu, 2 Nov 2023 14:12:46 -0500 Subject: [PATCH] Fix slevomat link generation --- tools/inherited-rules.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 +}