-
-
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] Support directive image with target
resolves #911
- Loading branch information
Showing
11 changed files
with
611 additions
and
1 deletion.
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
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
62 changes: 62 additions & 0 deletions
62
packages/guides/src/ReferenceResolvers/ImageReferenceResolverPreRender.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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link https://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Guides\ReferenceResolvers; | ||
|
||
use phpDocumentor\Guides\NodeRenderers\PreRenderers\PreNodeRenderer; | ||
use phpDocumentor\Guides\Nodes\ImageNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
use phpDocumentor\Guides\RenderContext; | ||
use Psr\Log\LoggerInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
use function array_merge; | ||
use function sprintf; | ||
|
||
final class ImageReferenceResolverPreRender implements PreNodeRenderer | ||
{ | ||
public function __construct( | ||
private readonly DelegatingReferenceResolver $referenceResolver, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function supports(Node $node): bool | ||
{ | ||
return $node instanceof ImageNode; | ||
} | ||
|
||
public function execute(Node $node, RenderContext $renderContext): Node | ||
{ | ||
Assert::isInstanceOf($node, ImageNode::class); | ||
if ($node->getTarget() === null) { | ||
return $node; | ||
} | ||
|
||
$referenceLinkNode = $node->getTarget(); | ||
$messages = new Messages(); | ||
$resolved = $this->referenceResolver->resolve($referenceLinkNode, $renderContext, $messages); | ||
if (!$resolved) { | ||
$this->logger->warning( | ||
$messages->getLastWarning()?->getMessage() ?? sprintf( | ||
'Target %s of image could not be resolved in %s', | ||
$referenceLinkNode->getTargetReference(), | ||
$renderContext->getCurrentFileName(), | ||
), | ||
array_merge($renderContext->getLoggerInformation(), $messages->getLastWarning()?->getDebugInfo() ?? []), | ||
); | ||
} | ||
|
||
return $node; | ||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
tests/Integration/tests/images/image-target/expected/images/hero2-illustration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.