-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce exchangeable InterlinkParser
In TYPO3 we want to allow additonal special signs, so that interlinks to composer names can be made. Additionally, this also removed duplicate code
- Loading branch information
Showing
8 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/guides-restructured-text/src/RestructuredText/Parser/DefaultInterlinkParser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Parser; | ||
|
||
use function preg_match; | ||
|
||
final class DefaultInterlinkParser implements InterlinkParser | ||
{ | ||
/** @see https://regex101.com/r/htMn5p/1 */ | ||
private const INTERLINK_REGEX = '/^([a-zA-Z0-9-_]+):(.*$)/'; | ||
|
||
/** @return array{interlink:?string,reference:string} */ | ||
public function extractInterlink(string $fullReference): array | ||
{ | ||
if (!preg_match(self::INTERLINK_REGEX, $fullReference, $matches)) { | ||
return ['interlink' => null, 'reference' => $fullReference]; | ||
} | ||
|
||
$interlink = $matches[1] === '' ? null : $matches[1]; | ||
$reference = $matches[2]; | ||
|
||
return ['interlink' => $interlink, 'reference' => $reference]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/guides-restructured-text/src/RestructuredText/Parser/InterlinkParser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\RestructuredText\Parser; | ||
|
||
interface InterlinkParser | ||
{ | ||
/** @return array{interlink:?string,reference:string} */ | ||
public function extractInterlink(string $fullReference): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters