#8413·tiptap

Markdown: serialize() does not escape "!" before a link, so the link comes back as an image`

Author: zsilbiCreated Sep 29, 2026Updated Sep 29, 2026
Labelsstatus: triagearea: markdowncomplexity: easyimpact: low

Affected Packages

@tiptap/markdown

Tiptap Version

3.31.3

Browser Used

Not browser-specific

What happened?

MarkdownManager.serialize() does not escape a ! at the end of a text node that is followed by a link. The output ![text](url) is image syntax, so when the output is parsed again, the link becomes an image node.

Saving and reopening the Markdown changes a link into an image. When the reparsed content is rendered, this can cause an unintended image request to the original link URL.

Reproduction

typescript
import { MarkdownManager } from '@tiptap/markdown'
import StarterKit from '@tiptap/starter-kit'
import Image from '@tiptap/extension-image'

const manager = new MarkdownManager({ extensions: [StarterKit, Image] })

for (const input of [
  'Great news\\![the post](https://example.com/p)',
  'Great news!<https://example.com/p>',
]) {
  const before = manager.parse(input)
  const output = manager.serialize(before)
  const after = manager.parse(output)

  console.log(JSON.stringify({ input, before, output, after }))
}

Expected Behavior

The text Great news! followed by a link, before and after the round trip. For example, serialize() writes Great news\![the post](https://example.com/p).

Actual

Input serialize() output Parse of the output
Great news\![the post](https://example.com/p) Great news![the post](https://example.com/p) image node
Great news!<https://example.com/p> Great news![https://example.com/p](https://example.com/p) image node

The first parse has a link and no image node. The parse of the output has an image whose src is the original link URL.

Reproducible Example URL (Optional)

No response

Additional Context (Optional)

Possible fix: Escape a literal ! when it would otherwise combine with the following link's opening [ to form image syntax. This needs to account for mark boundaries.

Related

  • #8025 proposed broader punctuation escaping, including !, but was closed without merging because it escaped too much and caused unrelated test regressions. The maintainer suggested a context-aware implementation.
  • #8374 reports lost angle brackets around link and image destinations. The same defect can also create an image when a link destination contains Markdown syntax: [x](<https://example.com/a)![y](https://example.com/img.png>) → [x](https://example.com/a)![y](https://example.com/img.png), which parses as a link and an image. This is a separate case from the literal ! before a link reported here.
  • #8140 proposes escaping block syntax at the start of a paragraph. It does not address this inline case.

This can matter when an application accepts untrusted Markdown and treats links differently from images. Content initially parsed as a link can become an image after saving and reopening. The reproduction demonstrates the node conversion; it does not test browser requests or an application's URL-validation behavior.