Skip to content

Commit

Permalink
[FEATURE] Handle image titles in Markdown
Browse files Browse the repository at this point in the history
Resolves #1095

(cherry picked from commit 593a27d)
  • Loading branch information
linawolf committed Oct 3, 2024
1 parent d8d4866 commit 4744ca9
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 4744ca9

Please sign in to comment.