Skip to content

Formatting and nested images inside an image description are destroyed on save #259

Description

@Azganoth

Summary

An image's alt text is held as a plain string, so anything structured inside it is destroyed when the file is opened and gone from the file after one save. Emphasis, inline code, and a nested image are all flattened to their text, and the loss is silent and permanent.

Unlike the other authored-form defects under #251, this is content loss rather than a rewrite: the markers and the inner image cannot be recovered from the saved file.

Steps to reproduce

  1. Open a document containing ![Alt with *emphasis* and \code`](../assets/leaf.svg)`.
  2. Save it.
  3. Read the file.

Expected behavior

The alt text keeps the content the author wrote. CommonMark allows inline content inside an image description, and corpus/commonmark/links-and-images.md covers both forms.

Actual behavior

Measured against 9626471d by driving the editor mount used by the plugin tests. Both rows are stable across a second save, so the corpus guard is green on both:

Document Saved
![Alt with *emphasis* and \code`](../assets/leaf.svg)` ![Alt with emphasis and code](../assets/leaf.svg)
![Outer ![inner](../assets/leaf.svg)](../assets/leaf.svg) ![Outer inner](../assets/leaf.svg)

The second row destroys the inner image entirely; its destination is not in the saved file anywhere.

Related context

Done when

  • Emphasis, strong, inline code, and strikethrough inside an image description survive an open and a save.
  • An image nested inside another image's description survives an open and a save, or the reason it cannot is recorded with the behavior the editor gives instead.
  • Regression coverage asserts the document rather than only the serialized bytes, since both forms converge today and the corpus guard cannot see either one.
  • The owning documentation records what an image description may hold if the accepted answer narrows it.

Notes, logs, screenshots

Diagnosis

The image node carries its description as an alt string attribute rather than as inline children, so the parse discards everything but the text. Both the corpus guard in src/features/editor/tests/corpusRoundTrip.test.tsx and the serializer are blind to it: the flattened form converges perfectly, which is exactly the failure mode #251 records under A green corpus guard does not mean a sub-issue worked.

Implementation direction

The image schema comes from @milkdown/preset-commonmark, so this is likely a local schema override in createMilkdownEditor.ts, which already carries that pattern for hardbreakSchema and linkSchema. #251 also records the trap that extendSchema registers a new slice, so an override on a schema reached that way never lands.

Nested images may be worth separating from the mark case once the schema question is answered; the mark case is the common one and the corpus covers it directly.

Out of scope

  • Link labels, which already carry inline children and keep their formatting.
  • The escaping and normalization differences in the same corpus file, which are filed on their own.

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Projects

Status
Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions