Skip to content

Commit 42f3ecf

Browse files
committed
[FEATURE] Handle image titles in Markdown
Resolves #1095
1 parent 340bf29 commit 42f3ecf

File tree

8 files changed

+392
-3
lines changed

8 files changed

+392
-3
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +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)
23+
public function __construct(
24+
private readonly string $url,
25+
private readonly string $altText,
26+
private readonly string $title,
27+
)
2428
{
2529
parent::__construct(self::TYPE, $url);
2630
}
@@ -34,4 +38,9 @@ public function getAltText(): string
3438
{
3539
return $this->altText;
3640
}
41+
42+
public function getTitle(): string
43+
{
44+
return $this->title;
45+
}
3746
}
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)