Skip to content

Commit

Permalink
Update Markdown link support to work without single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 24, 2024
1 parent 33ba914 commit 15ecda8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public static function postprocess(string $html): string
protected static function patterns(): array
{
return [
'/<a href="hyde::route\(\'([^\']+)\'\)"/' => function (array $matches): string {
return '<a href="'.Hyde::route($matches[1]).'"';
'/<a href="hyde::route\(([\'"]?)([^\'"]+)\1\)"/' => function (array $matches): string {
return '<a href="'.Hyde::route($matches[2]).'"';
},
'/<a href="hyde::relativeLink\(\'([^\']+)\'\)"/' => function (array $matches): string {
return '<a href="'.Hyde::relativeLink($matches[1]).'"';
'/<a href="hyde::relativeLink\(([\'"]?)([^\'"]+)\1\)"/' => function (array $matches): string {
return '<a href="'.Hyde::relativeLink($matches[2]).'"';
},
'/<img src="hyde::asset\(\'([^\']+)\'\)"/' => function (array $matches): string {
return '<img src="'.Hyde::asset($matches[1]).'"';
'/<img src="hyde::asset\(([\'"]?)([^\'"]+)\1\)"/' => function (array $matches): string {
return '<img src="'.Hyde::asset($matches[2]).'"';
},
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,29 @@ public function testRouteReplacement()
$input = '<p><a href="hyde::route(\'home\')">Home</a></p>';
$expected = '<p><a href="home.html">Home</a></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input));

$inputUnquoted = '<p><a href="hyde::route(home)">Home</a></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($inputUnquoted));
}

public function testRelativeLinkReplacement()
{
$input = '<p><a href="hyde::relativeLink(\'about\')">About</a></p>';
$expected = '<p><a href="about">About</a></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input));

$inputUnquoted = '<p><a href="hyde::relativeLink(about)">About</a></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($inputUnquoted));
}

public function testAssetReplacement()
{
$input = '<p><img src="hyde::asset(\'image.jpg\')" alt="Image" /></p>';
$expected = '<p><img src="media/image.jpg" alt="Image" /></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input));

$inputUnquoted = '<p><img src="hyde::asset(image.jpg)" alt="Image" /></p>';
$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($inputUnquoted));
}

public function testMultipleReplacements()
Expand All @@ -67,6 +76,14 @@ public function testMultipleReplacements()
HTML;

$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input));

$inputUnquoted = <<<'MARKDOWN'
<a href="hyde::route(home)">Home</a>
<a href="hyde::relativeLink(about)">About</a>
<img src="hyde::asset(logo.png)" alt="Logo" />
MARKDOWN;

$this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($inputUnquoted));
}

public function testNoReplacements()
Expand Down

0 comments on commit 15ecda8

Please sign in to comment.