Skip to content

Commit b10c511

Browse files
committed
[FEATURE] Handle image titles in Markdown
Resolves #1095
1 parent 9bc8130 commit b10c511

File tree

8 files changed

+392
-4
lines changed

8 files changed

+392
-4
lines changed

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/InlineImageParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null
5252
);
5353
}
5454

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

5858
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<img src="{%- if node.value is external_target -%} {{ node.value }} {%- else -%} {{ asset(node.value) }} {%- endif -%}" alt="{{- node.altText -}}"/>
1+
<img src="{%- if node.value is external_target -%} {{ node.value }} {%- else -%} {{ asset(node.value) }} {%- endif -%}" alt="{{- node.altText -}}"
2+
{%- if node.title %} title="{{- node.title -}}" {%- endif -%}/>

packages/guides/src/Nodes/Inline/ImageInlineNode.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ final class ImageInlineNode extends InlineNode
2020
{
2121
public const TYPE = 'image';
2222

23-
public function __construct(private readonly string $url, private readonly string $altText)
24-
{
23+
public function __construct(
24+
private readonly string $url,
25+
private readonly string $altText,
26+
private readonly string|null $title = null,
27+
) {
2528
parent::__construct(self::TYPE, $url);
2629
}
2730

@@ -34,4 +37,9 @@ public function getAltText(): string
3437
{
3538
return $this->altText;
3639
}
40+
41+
public function getTitle(): string
42+
{
43+
return $this->title ?? '';
44+
}
3745
}
Lines changed: 180 additions & 0 deletions
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- content start -->
2+
<div class="section" id="markdown-image">
3+
<h1>Markdown Image</h1>
4+
5+
<p><img src="/hero-illustration.svg" alt="Hero Illustrations" title="Some title"/></p>
6+
7+
</div>
8+
<!-- content end -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
5+
input-format="md"
6+
>
7+
<project title="Project Title" version="6.4"/>
8+
</guides>

0 commit comments

Comments
 (0)