Skip to content

Don't remove stars from alt attribute of an image #44

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

Closed
4 tasks done
talatkuyuk opened this issue Apr 28, 2025 · 1 comment
Closed
4 tasks done

Don't remove stars from alt attribute of an image #44

talatkuyuk opened this issue Apr 28, 2025 · 1 comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@talatkuyuk
Copy link

Initial checklist

Affected package

mdast-util-from-markdown

Steps to reproduce

const input = '![*text*](image.png "*title*")';

console.dir(fromMarkdown(input), {depth: null});

Actual behavior

It removes the stars from "alt", keeps stars in "title"

{
  "alt": "text",
  "title": "*title*",
  "type": "image",
  "url": "image.png",
},

Expected behavior

It should keep stars in "alt" as well.

{
  "alt": "*text*",
  "title": "*title*",
  "type": "image",
  "url": "image.png",
},

But, I see that commonmark specs also removes stars from "alt". I couldn't get the rationale of removing stars from "alt", whileas doesn't remove stars from "title". It would be better to keep stars in "alt", so I would use it as a directive for images for transformation in a plugin.

I know, you will close the issue pointing commonmark specs. I just wanted to know the rationale in commonmark specs?

(why I opened this issue is because the next question will be why curly braces are also removed from "alt" attribute of an image when remark-mdx parse it; at least I would expect curly braces are kept in "alt" when remark-mdx parse it since commonmark specs also keeps the curly braces in alt attribute. This issue is critic for me because of this discussion)

Runtime

node@latest

Package manager

npm@latest

Operating system

macos@latest

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Apr 28, 2025
@ChristianMurphy
Copy link
Member

It comes from this line in the spec

Though this spec is concerned with parsing, not rendering, it is recommended that in rendering to HTML, only the plain string content of the image description be used.

https://spec.commonmark.org/0.31.2/#example-575

And is because alt is intended for screen readers and extra symbols are for sighted users and are handled inconsistency (at best) by screen readers, traditionally asterisk are ignored by screen readers and should not be included in text or alt text intended to be consumed by a reader.
https://www.deque.com/blog/dont-screen-readers-read-whats-screen-part-1-punctuation-typographic-symbols/

@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Apr 28, 2025
@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants