Skip to content

Commit

Permalink
Merge pull request #1119 from phpDocumentor/backport/1.x/pr-1113
Browse files Browse the repository at this point in the history
[1.x] Merge pull request #1113 from phpDocumentor/task/md-image
  • Loading branch information
phpdoc-bot authored Oct 3, 2024
2 parents d8d4866 + 4744ca9 commit 420a7cf
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null
);
}

return new ImageInlineNode($commonMarkNode->getUrl(), $content ?? '');
return new ImageInlineNode($commonMarkNode->getUrl(), $content ?? '', $commonMarkNode->getTitle() ?? '');
}

protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<img src="{%- if node.value is external_target -%} {{ node.value }} {%- else -%} {{ asset(node.value) }} {%- endif -%}" alt="{{- node.altText -}}"/>
<img src="{%- if node.value is external_target -%} {{ node.value }} {%- else -%} {{ asset(node.value) }} {%- endif -%}" alt="{{- node.altText -}}"
{%- if node.title %} title="{{- node.title -}}" {%- endif -%}/>
12 changes: 10 additions & 2 deletions packages/guides/src/Nodes/Inline/ImageInlineNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ final class ImageInlineNode extends InlineNode
{
public const TYPE = 'image';

public function __construct(private readonly string $url, private readonly string $altText)
{
public function __construct(
private readonly string $url,
private readonly string $altText,
private readonly string|null $title = null,
) {
parent::__construct(self::TYPE, $url);
}

Expand All @@ -34,4 +37,9 @@ public function getAltText(): string
{
return $this->altText;
}

public function getTitle(): string
{
return $this->title ?? '';
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- content start -->
<div class="section" id="markdown-image">
<h1>Markdown Image</h1>

<p><img src="/hero-illustration.svg" alt="Hero Illustrations" title="Some title"/></p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<guides xmlns="https://www.phpdoc.org/guides"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
input-format="md"
>
<project title="Project Title" version="6.4"/>
</guides>
Loading

0 comments on commit 420a7cf

Please sign in to comment.