Skip to content

fix(markdown): keep inline code fences and image alt text across round trips - #585

Open
Chandra-Prakash-TS wants to merge 1 commit into
StackExchange:mainfrom
Chandra-Prakash-TS:fix/markdown-roundtrip-code-alt
Open

Chandra-Prakash-TS wants to merge 1 commit into
StackExchange:mainfrom
Chandra-Prakash-TS:fix/markdown-roundtrip-code-alt

Conversation

@Chandra-Prakash-TS

Copy link
Copy Markdown

Closes #572.

Describe your changes

Both bugs from the issue, each in one place:

  1. Inline code fences grow on every Rich Text round trip. The code mark serializer takes the default delimiter from prosemirror-markdown, which is already long enough for the backticks in the code (e.g. "" for hello ), and then replaced its first backtick with the stored markup (e.g. ""). That adds markup.length - 1 backticks per round trip. applyCodeMarkup now keeps the default backtick run and only swaps in the original markup when it is longer, so a fence like ``test`` is still preserved. <code> markup is handled as before.
  2. Image alt text is cut after the first inline token. The image parser fell back to tok.children[0].content, so ![my *cool* pic](...), ![Tom &amp; Jerry](...), ![C\# logo](...) and ![array[0]](...) lost everything after the first child. It now joins the content of all children, which matches the plain-text alt markdown-it renders.

A patch changeset is included.

PR Checklist

  • All new/changed functionality includes unit and (optionally) e2e tests as appropriate
  • All new/changed functions have /** ... */ docs
  • I've added the bug/enhancement and other labels as appropriate

Environment(s) tested

  • Device: desktop
  • OS: macOS
  • Browser: jsdom (Jest unit tests)
  • Version: N/A

Additional context

New cases in test/shared/markdown-serializer.test.ts cover the code fences ( test , `ab``, `` ``` a``b ``` ``, ``` ``test`` ```) and the alt text examples from the issue. Six of them fail without the change and all pass with it.npm run test:unit, prettier --checkandeslint` pass.

@Chandra-Prakash-TS
Chandra-Prakash-TS requested a review from a team as a code owner November 30, 2026 17:40

This branch has not been deployed

No deployments
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.

Markdown round-trip grows inline-code backtick fences and truncates image alt text

1 participant