Skip to content

fix(image): keep data: URI images on markdown round-trip - #9159

Open
guillaume-flambard wants to merge 1 commit into
nextcloud:mainfrom
guillaume-flambard:fix/data-uri-images-9108
Open

fix(image): keep data: URI images on markdown round-trip#9159
guillaume-flambard wants to merge 1 commit into
nextcloud:mainfrom
guillaume-flambard:fix/data-uri-images-9108

Conversation

@guillaume-flambard

Copy link
Copy Markdown

Fixes #9108.

Editing a markdown file that contains base64 images (data: URI) deleted those images from the file on the next save. The root cause sits in the image parse rules: both the block Image and ImageInline extensions exclude img[src^=data:] when the TipTap allowBase64 option is false, and nothing in this app turns it on. markdown-it parses the data: URI fine, but the img never becomes a document node, so the save writes the file without it. That exclusion is the upstream TipTap default, not a decision this app ever made, and there is nothing in the git history suggesting it was deliberate here.

The change enables allowBase64 on both extensions. The file content is the user's own and the editor's job is to preserve it, not to filter it. Rendering already goes through the ImageView node view, which handles the src as-is.

Regression test added in markdown.spec.js, covering both paths:

  • a standalone data: URI image (block level, wrapped in a figure)
  • an inline data: URI image inside a paragraph

Both round-trip through the editor byte-identical. Full unit suite: 1582/1582 across 50 files. Before the change the new test fails (the image is dropped), which is the reported data loss.

Markdown files can legitimately contain base64 images. Both image parse
rules excluded img[src^=data:] because the TipTap allowBase64 option
defaults to false, so those images never made it into the document and
were silently dropped from the file on the next save (nextcloud#9108).

Enable allowBase64 on the Image and ImageInline extensions: the file
content is the user's own, and the editor is expected to preserve it,
not to filter it. Regression test covers both the block (figure) and
the inline image path.

Signed-off-by: Guillaume Flambard <g.flambard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Editing a Markdown file with inline (data: URI) images deletes them from the file

1 participant