jsx approved image alt text #1578
Labels
🏡 area/internal
This affects the hidden internals
good first issue 👋
This may be a great place to get started!
🐛 type/bug
This is a problem
💎 v2
Issues related to v2
🙆 yes/confirmed
This is confirmed and ready to be worked on
Subject of the issue
tl;dr quotes in image alt text break babel because they don't get appropriately turned into jsx expressions (since jsx strings don't support
\"
in them)Hi! I found that if someone uses quotation marks in their image alt (
![something really "cool"](https://www.humanesociety.org/sites/default/files/styles/1240x698/public/2020-07/kitten-510651.jpg)
), the outputted jsx is<img src="https://www.humanesociety.org/sites/default/files/styles/1240x698/public/2020-07/kitten-510651.jpg" alt="something really \"cool\"" parentName="p" />
Which causes babel to blow up because having escaped " marks in a JSX string is not supported turns out! This comment really helped me figure that out. So! I think the solution is to make sure that if an image alt has quotes, those should appropriately be wrapped in a jsx expression{}
.Disclaimers: I think this should be on MDX since remark is agnostic to jsx. However, I noticed this wasn't an issue with the link text (Like
[link text "here"](blah.com)
) and that gets handled just fine (aka gets wrapped in appropriate curly braces)--unsure if that was because of something in this project or in remark.Your environment
Steps to reproduce
![something really "cool"](https://www.humanesociety.org/sites/default/files/styles/1240x698/public/2020-07/kitten-510651.jpg)
in it somewheretransformAsync
from babel core with presetReact & presetEnv)🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉
Expected behaviour
Babel is happy and outputs functioning code!
Actual behaviour
Babel is sad and says "SyntaxError: unknown: Expecting Unicode escape sequence \uXXXX"
Work around
For now I'm making a quick remark plugin that replaces double quotes with
"
! This definitely feels more like a bandaid than a real solution but want to share in case anyone hits this issue and needs a quick fixThe text was updated successfully, but these errors were encountered: