Skip to content
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

Bug: Different empty alt values for image, imageReference #103

Closed
quantizor opened this issue Dec 7, 2015 · 3 comments
Closed

Bug: Different empty alt values for image, imageReference #103

quantizor opened this issue Dec 7, 2015 · 3 comments
Assignees
Labels
remark 🐛 type/bug This is a problem
Milestone

Comments

@quantizor
Copy link

using mdast.parse():

mdast.parse("![](/xyz.png)")

Yields an AST node for image with alt set to null.

The same setup but using an imageReference instead:

mdast.parse("![][1]\n[1]: /xyz.png")

Yields an imageReference with alt set to "" (empty string)

@wooorm
Copy link
Member

wooorm commented Dec 7, 2015

I agree, that isn’t very pretty. I’d go for the following here:

 } else if (type === 'image') {
-    node.alt = decode(self.descape(text), eat);
+    node.alt = decode(self.descape(text), eat) || null;
 }

The reason for null is because it’s in the imageReference definition.

Not that I suggest accept both null and undefined next to "", everywhere. It makes for more solid code. Although you’re building with mdast ingrained right now, maybe in the future you’ll allow plug-ins to manipulate the tree too, in which case they might (probably will) sometimes forget to add a property.

@wooorm wooorm changed the title imageReference without alt is empty string instead of null Bug: Different empty alt values for image, imageReference Dec 7, 2015
@wooorm wooorm added this to the 3.0.0 milestone Dec 14, 2015
@wooorm wooorm self-assigned this Dec 14, 2015
@wooorm
Copy link
Member

wooorm commented Dec 14, 2015

This will be included in the upcoming release of mdast, 3.0.0, which I’ll expect to 🚢 before the new year.

@quantizor
Copy link
Author

🎉

wooorm added a commit that referenced this issue Dec 18, 2015
In the below example, the image node had an `alt` property set to `null`,
whereas the reference had an `alt` set to `""`.

```md
![](/xyz.png)

![][1]

[1]: /xyz.png
```

This update ensures both have `null` as the value corresponding to an
empty `alt`.

Closes GH-103.
@wooorm wooorm closed this as completed in 698d569 Dec 24, 2015
@wooorm wooorm added 🐛 type/bug This is a problem remark labels Jan 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
remark 🐛 type/bug This is a problem
Development

No branches or pull requests

2 participants