Skip to content

fix(editors): keep links and emoji in rich text code blocks - #238

Merged
StephenTangCook merged 1 commit into
mainfrom
claude/rich-text-code-block-inlines
Oct 12, 2026
Merged

StephenTangCook merged 1 commit into
mainfrom
claude/rich-text-code-block-inlines

Conversation

@StephenTangCook

@StephenTangCook StephenTangCook commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A rich text code block (rich_text_preformatted) holding anything but plain text now opens in the structured editor. Before, the WYSIWYG opened it and the next edit silently deleted its links, emoji and styled text.

Why

The WYSIWYG's code block holds plain text only. blockElementToPM keeps just the text runs. But detectLossy checked a code block's inlines with the same rules as a paragraph, which allow link and emoji and the bold/italic/strike/underline/code styles. So it reported the block as safe to round-trip:

const block = { type: 'rich_text', elements: [{ type: 'rich_text_preformatted', elements: [
  { type: 'text', text: 'see ' }, { type: 'link', url: 'https://x.test' }, { type: 'emoji', name: 'wave' }
] }] };
detectLossy(block);                                   // [] — before this change
proseMirrorToRichText(richTextToProseMirror(block));  // only { type: 'text', text: 'see ' } survives

detectLossy now flags each non-text inline in a code block (In code block: link) and each styled text run (Styled text in code block). Plain-text code blocks, the WYSIWYG's own output, still edit in the WYSIWYG. A code block's inlines are reported once, so an unsupported inline there (say, a channel mention) isn't also listed as Inline: channel.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test: 647 tests pass (522 unit, 125 Storybook browser), run project by project against a pre-provisioned Chromium (BK_CHROMIUM_EXECUTABLE).
  • New test/rich-text-tiptap-code-block.test.ts:
    • A plain-text code block round-trips.
    • A link, an emoji or styled text in a code block is flagged, and an unsupported inline there is reported once.
    • Links and emoji outside code blocks still stay in the WYSIWYG.
    • RichTextEditor opens a code block holding a link in structured mode.
    • The four tests covering the bug fail on main.

Notes for reviewer

#237 (the @ mention picker) needs to flag a mention in a code block too. I'm updating it to carry this same detectLossy hunk, so the two PRs merge cleanly in either order.


🤖 Generated with Claude Code

https://claude.ai/code/session_01MTy6g5wxP9DqjWJQshGz51


Generated by Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

The WYSIWYG keeps only a code block's plain text, but detectLossy passed
links, emoji and styled text inside a rich_text_preformatted, so the next
edit silently deleted them. A code block holding anything but plain text
now opens in the structured editor instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MTy6g5wxP9DqjWJQshGz51
@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare preview

✅ Deployed 2f8560f · Branch preview · Commit preview · Build logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
block-kitchen 2f8560f Commit Preview URL

Branch Preview URL
Oct 12 2026, 02:01 PM

@StephenTangCook
StephenTangCook merged commit 72e93fc into main Oct 12, 2026
12 of 13 checks passed
@StephenTangCook
StephenTangCook deleted the claude/rich-text-code-block-inlines branch October 12, 2026 14:22
StephenTangCook pushed a commit that referenced this pull request Oct 12, 2026
Generalize the mention-in-code-block check to every non-text inline and
styled text run, matching #238, so the two
changes merge cleanly in either order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MTy6g5wxP9DqjWJQshGz51
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.

2 participants