-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix image srcset parsing #7702
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
base: main
Are you sure you want to change the base?
Fix image srcset parsing #7702
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
If the goal here is to support srcset, why not add srcset to the ImageNode model instead of trying to downgrade srcset by parsing it as src? |
Maybe some downgrade is only needed for exporting to Markdown... Another related useful feature to src parsing/formatting I used (and would be great to have more support for it in stock ImageNode) is specifying an url-prefix for the ImageNode (e.g. This is useful to keep the markdown/html lean and manage the images prefix via the SSG configuration. |
Downgrading the model of components because Markdown might not support some feature isn't really something that makes sense in the general case. You could always do the downgrade during markdown export. |
Exactly, I'm of course proposing to move the downgrader from this PR into the ImageNode markdown exporter code |
Technically I like the idea but how is that useful in a real-world context? Afaik srcset is typically generated serverside, as it's too much configuration for a user to bother with. |
Anyone using images in a properly written rich text editor will have server-side code involved to handle image uploads, why wouldn't it support srcset? |
[lexical-playground] Feature: Add srcset support for image paste handling
Description
Currently, when pasting HTML content that contains images with
srcset
attributes instead of (or in addition to)src
attributes, the Lexical image plugin fails to properly convert these images. This results in either:src
valuesThis PR adds comprehensive support for handling
srcset
attributes when pasting images into the Lexical editor. The solution includes:Changes Made
Created
imageUtils.ts
utility module withgetImageSource()
function that:img
elementsrc
andsrcset
attributessrcset
formats (width descriptors, density descriptors, no descriptors)srcset
by falling back tosrc
Updated image conversion functions:
$convertImageElement
inImageNode.tsx
$convertInlineImageElement
inInlineImageNode.tsx
getImageSource()
utility functionAdded comprehensive testing:
Features Supported
srcset="image1.jpg 300w, image2.jpg 600w"
srcset="image1.jpg 1x, image2.jpg 2x"
srcset="image1.jpg, image2.jpg"
src
attributeCloses #
Test plan
Before
When pasting HTML content with images that have
srcset
attributes:The image would either:
src
valueAfter
The same HTML content now properly converts the image, extracting the appropriate source from the
srcset
attribute:Test Coverage
Unit Tests: 7/7 passing ✅
E2E Tests: 7 test cases created for real-world paste scenarios