Skip to content

Support spaces in Markdown image alt text - #1878

Open
singye3 wants to merge 1 commit into
ruby:masterfrom
singye3:fix-image-alt-with-spaces
Open

singye3 wants to merge 1 commit into
ruby:masterfrom
singye3:fix-image-alt-with-spaces

Conversation

@singye3

@singye3 singye3 commented Nov 19, 2026

Copy link
Copy Markdown

The Markdown parser turns ![Alt text](image.png) into rdoc-image:image.png:Alt text. A bare rdoc-* link ends at the first whitespace, so this rendered as <img src="image.png" alt="Alt"> text. Adjacent images and images with absolute URLs broke the same way. Fixes #1870.

When the alt text contains whitespace, the parser now wraps the link in braces, {rdoc-image:image.png:Alt text}, and the RDOCLINK regexp matches the braced form as one link. ToHtml and ToMarkdown remove the braces before handling it. Alt text without whitespace, or with braces, keeps the bare form, so that output does not change.

Image links like [![Alt text](image.png)](url) keep their current output, since a tidy link label already accepts spaces in an rdoc-image alt. For a heading made of an image, Heading ignores the braces when it builds the table of contents text and the legacy anchor. Existing anchors stay the same, and the heading HTML now gets the full alt text.

I left the braced form out of the RDoc markup reference because it mainly exists for Markdown conversion. Happy to document it if you would like it to be public syntax.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spaces in image alt texts are not supported

1 participant