Skip to content

[FEATURE] Handle image titles in Markdown #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading