Skip to content

Commit

Permalink
Extract helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 24, 2024
1 parent 6ec38dd commit eabee96
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ class DynamicMarkdownLinkProcessor implements MarkdownPostProcessorContract
{
public static function postprocess(string $html): string
{
/** @var array<string, callable(array<int, string>): string> $patterns */
$patterns = [
foreach (static::patterns() as $pattern => $replacement) {
$html = preg_replace_callback($pattern, $replacement, $html);
}

return $html;
}

/** @return array<string, callable(array<int, string>): string> */
protected static function patterns(): array
{
return [
'/<a href="hyde::route\(\'([^\']+)\'\)"/' => function (array $matches): string {
return '<a href="'.Hyde::route($matches[1]).'"';
},
Expand All @@ -23,11 +32,5 @@ public static function postprocess(string $html): string
return '<img src="'.Hyde::asset($matches[1]).'"';
},
];

foreach ($patterns as $pattern => $replacement) {
$html = preg_replace_callback($pattern, $replacement, $html);
}

return $html;
}
}

0 comments on commit eabee96

Please sign in to comment.