Skip to content

fix(table): preserve hardBreak nodes during markdown cell serialization - #7738

Closed
sahiee-dev wants to merge 1 commit into
ueberdosis:mainfrom
sahiee-dev:fix/table-cell-br-serialization-7731
Closed

sahiee-dev wants to merge 1 commit into
ueberdosis:mainfrom
sahiee-dev:fix/table-cell-br-serialization-7731

Conversation

@sahiee-dev

Copy link
Copy Markdown
Contributor

Changes Overview

Fixes data loss where <br> tags inside markdown table cells are silently dropped during re serialization via editor.storage.markdown.getMarkdown(), collapsing multi line cell content into a single line.

Implementation Approach

extension-hard-break correctly serializes <br> as \n (CommonMark spec). The data loss occurs in extension-table's collapseWhitespace(), which strips all \s+ including that \n before writing the cell back to markdown.

The fix intercepts hardBreak's exact output ( \n) and converts it to <br> before collapseWhitespace() runs:

// COUPLING WARNING: Tiptap's extension-hard-break hardcodes its markdown output to `  \n`
// (defined in packages/extension-hard-break/src/hard-break.ts).
// Because node renderers don't receive contextual metadata (like "inside a table cell"),
// the hardBreak node has no way to change its output to `<br>` contextually.
// We intercept `  \n` here before collapseWhitespace blindly strips it.
// If extension-hard-break ever changes its serialization string, this MUST be updated.
const HARDBREAK_MARKDOWN_PATTERN = '  \n'
raw = raw.replaceAll(HARDBREAK_MARKDOWN_PATTERN, cellSep)

I investigated passing table cell context down to hardBreak so it could emit <br> directly, but h.renderChildren does not propagate meta across recursion boundaries that would require a broader MarkdownManager refactor.

Also updated DEFAULT_CELL_LINE_SEPARATOR from \u001F to <br> for consistency with the preserved output format.

Testing Done

Added a round trip test in packages/extension-table/__tests__/tableMarkdown.spec.ts, with HardBreak registered in the test markdown manager:

it('should preserve <br> line breaks inside table cells during round-trip serialization', () => {
  const markdown = `| desc |\n| --- |\n| foo<br>bar |`
  const parsed = markdownManager.parse(markdown)
  const serialized = markdownManager.serialize(parsed)
  expect(serialized).toContain('foo<br>bar')
  expect(serialized).not.toContain('foo bar')
})

All extension-table tests pass.

Verification Steps

  1. Open the Tiptap markdown editor
  2. Paste the following markdown:
|    desc     |
|   :-----:   |
| foo<br>bar  |
  1. Call editor.storage.markdown.getMarkdown()
  2. Confirm the output contains foo<br>bar and not foo bar

Additional Notes

packages/markdown/__tests__/paragraph.spec.ts has a pre existing failure on the upstream develop branch unrelated to this change verified by running it against a clean develop branch before and after applying this fix.

Checklist

Related Issues

Closes #7731

@changeset-bot

changeset-bot Bot commented Apr 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dfbe77e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify

netlify Bot commented Apr 12, 2026

Copy link
Copy Markdown

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit dfbe77e
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/69db83e3055bb5000824892c
😎 Deploy Preview https://deploy-preview-7738--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bdbch

bdbch commented Jul 16, 2026

Copy link
Copy Markdown
Member

Closing this in favor for #8012

@bdbch bdbch closed this Jul 16, 2026
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.

Table cell line breaks (<br>) are lost when extracting Markdown from editor

2 participants