Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<img
src="{{ asset(node.value) }}"
src="{%- if node.value is external_target -%} {{ node.value }} {%- else -%} {{ asset(node.value) }} {%- endif -%}"
{% if node.hasOption('width') %}width="{{ node.option('width') }}"{% endif%}
{% if node.hasOption('height') %}height="{{ node.option('height') }}"{% endif%}
{% if node.hasOption('align') %}align="{{ node.option('align') }}"{% endif%}
Expand Down
7 changes: 7 additions & 0 deletions packages/guides/src/Twig/AssetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace phpDocumentor\Guides\Twig;

use League\Flysystem\Exception;
use League\Uri\Uri;
use League\Uri\UriInfo;
use LogicException;
use phpDocumentor\Guides\Meta\InternalTarget;
use phpDocumentor\Guides\Meta\Target;
Expand All @@ -26,6 +28,7 @@
use phpDocumentor\Guides\UrlGeneratorInterface;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Stringable;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\TwigTest;
Expand Down Expand Up @@ -66,6 +69,10 @@ public function getTests(): array
/** @param mixed $value */
static fn (mixed $value): bool => $value instanceof Node,
),
new TwigTest(
'external_target',
static fn (string|Stringable $value): bool => UriInfo::isAbsolute(Uri::createFromString($value)),
),
];
}

Expand Down
4 changes: 4 additions & 0 deletions packages/guides/src/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ final class UrlGenerator implements UrlGeneratorInterface
public function absoluteUrl(string $basePath, string $url): string
{
$uri = UriFactory::createUri($url);
if (UriInfo::isAbsolute($uri)) {
return $url;
}

if (UriInfo::isAbsolutePath($uri)) {
return $url;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/tests/image-fullurl/image-fullurl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>Test</p>
<img src="https://img.shields.io/github/contributors/ORG/REPO" />
3 changes: 3 additions & 0 deletions tests/Functional/tests/image-fullurl/image-fullurl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test

.. image:: https://img.shields.io/github/contributors/ORG/REPO