facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.62k stars 1.67k forks source link

Bug: inline images are not being exported to Markdown at all (verified in playground) and image captions are not exported to Markdown/DOM (instead some other text is used in alt) #5474

Open vadimkantorov opened 9 months ago

vadimkantorov commented 9 months ago

I went to https://playground.lexical.dev/, inserted an inline image, it gets displayed okay. I then press the button for converting to Markdown. The markdown string contains no info about the image.

I understand that there often is no 1:1 correspondence between the JSON editor state and markdown, but images (inline or URL-based) can somehow be represented by markdown (e.g. by slightly abusing Markdown and using datauri in the ![](imagedatauri) syntax or by returning a dictionary of attachment files along with markdown string which are then addressed by image tags)

I've checked, regular "Insert Image" (non-inline) gets converted to markdown using the datauri syntax, but somehow inline image is not. I think it'd be better in this case to trim the precise inline formatting and still preserve the presence of image instead of the current behavior of completely stripping the image (probably a markdown transformer for InlineImageNode would need to be added to packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts).

( Basically, I'm looking to create some basic rich-text editor like https://telegra.ph (quill-based), but using markdown + file attachments as backend (e.g. thing a GitHub repo containing images and markdown files) )

vadimkantorov commented 4 months ago

Maybe the better compromise would be to convert these inline images in Markdown as regular images (even if at inverse conversion they would be come regular images and not inline images), or maybe as images with some minor custom HTML

vadimkantorov commented 4 months ago

image

After clicking on M↓ nothing gets exported to markdown at all: image

vadimkantorov commented 4 months ago

Also, caption is not being exported to DOM for non-inline images: image

I would propose an option that image caption be exported as alt (at least for markdown it makes more sense). For DOM, maybe it can be exported as <figure><figcaption>...</figcaption><img ... /></figure>

kevinfairclough commented 3 months ago

Needs a FigurePlugin