Skip to content
New issue

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

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

Already on GitHub? # to your account

Image alt tag header formatting #1320

Merged
merged 5 commits into from
Mar 21, 2025

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Mar 20, 2025

This allows us to parse the alt text from Markdown images, formatting a header text correctly (using the alt text).

Without this PR, if a Markdown file has an image instead of a title, that image will be used in the table of contents, which is unreadable and undesirable.

Used in rack/rack#2313.

@ioquatix ioquatix force-pushed the image-alt-tag-header-formatting branch from d53617f to 9ef4934 Compare March 20, 2025 10:43
@ioquatix ioquatix requested review from nobu, st0012 and tompng March 20, 2025 10:44
{
# Extract alt text and URL
alt_text = a[/\{(.*?)\}/, 1] || ""
url = a[/\[(.*?)\]/, 1] || ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a is a String that always match to these regexp because ExplicitLink:a is created by "{#{l}}[#{s}]".
Perhaps it could be more simple if ExplicitLink returns structured data

  ExplicitLink =  Label:l "(" @Sp Source:s Spnl Title @Sp ")"
-                 { "{#{l}}[#{s}]" } # returns string, need to parse this string again...
+                 { { label: l, source: s } } # can return hash

(need to change Link = ExplicitLink | ReferenceLink | AutoLink to return a string if ExplicitLink returns hash)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this in a follow-up PR? I think it's out of scope for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

ioquatix and others added 3 commits March 21, 2025 11:08
@ioquatix ioquatix requested review from st0012 and tompng March 20, 2025 22:13
@st0012 st0012 added the bug label Mar 21, 2025
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@st0012 st0012 merged commit 894b2f1 into ruby:master Mar 21, 2025
30 checks passed
@ioquatix
Copy link
Member Author

Thanks everyone!

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

Successfully merging this pull request may close these issues.

3 participants