Skip to content

Fix markdown parsing for code blocks when withCodeBlocks is false#4804

Open
SylvainChevalier wants to merge 3 commits into
mainfrom
claude/determined-carson-71BwF
Open

Fix markdown parsing for code blocks when withCodeBlocks is false#4804
SylvainChevalier wants to merge 3 commits into
mainfrom
claude/determined-carson-71BwF

Conversation

@SylvainChevalier

@SylvainChevalier SylvainChevalier commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixed an issue where MDXEditor would throw a parsing error when encountering code blocks (``` fences) in markdown content when the withCodeBlocks prop is set to `false`. The code block plugin is now always registered to handle parsing of existing code blocks, while the `withCodeBlocks` flag continues to control only the UI affordances (toolbar button and rich editing experience).

Key Changes

  • Modified the plugin registration logic in InitializedMarkdownEditor to always include the codeBlockPlugin, regardless of the withCodeBlocks setting
  • The withCodeBlocks flag now only gates the insert-code-block toolbar affordance and the CodeMirror editing experience, not the parsing of existing code blocks
  • Added a test case to verify that existing code blocks render correctly in write mode when withCodeBlocks is false

Implementation Details

  • The plugin registration now uses a conditional that checks !withCodeBlocks || mode === "read" instead of returning early when withCodeBlocks is false
  • This ensures that pre-existing ``` fences in source markdown are properly parsed and don't cause MDXEditor to throw an error on unknown "code" nodes
  • The change maintains backward compatibility while fixing the parsing issue

https://claude.ai/code/session_01PZkycszwECr7vMhFzQKf56

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where existing fenced code blocks could cause Markdown parsing errors in the editor.
    • Ensured code blocks display correctly in read mode and when code-block editing is disabled.
  • Tests

    • Added coverage confirming surrounding text and existing code blocks render without errors.

… is off

The post background-information / notebook markdown / group description
fields render MarkdownEditor without withCodeBlocks, but content authored
elsewhere may still contain ``` fences. With no codeBlockPlugin
registered, MDXEditor throws "Parsing of the following markdown structure
failed: {type: code, name: N/A}".

Always register codeBlockPlugin with the read-only Prism descriptor so
existing fences parse; withCodeBlocks now only gates the insert-code-block
toolbar affordance and the rich CodeMirror editing path.
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9690b1d9-efaf-4708-a94d-6a5344d75bee

📥 Commits

Reviewing files that changed from the base of the PR and between c587f3d and 339d3b8.

📒 Files selected for processing (2)
  • front_end/src/components/markdown_editor/__tests__/initialized_editor.test.tsx
  • front_end/src/components/markdown_editor/initialized_editor.tsx

📝 Walkthrough

Walkthrough

The markdown editor now registers code-block parsing when rich code-block editing is disabled or the editor is in read mode. A write-mode test verifies fenced code blocks render without parsing errors and preserve surrounding text.

Changes

Fenced Code Block Parsing

Layer / File(s) Summary
Preserve fenced code parsing
front_end/src/components/markdown_editor/initialized_editor.tsx, front_end/src/components/markdown_editor/__tests__/initialized_editor.test.tsx
The editor retains codeBlockPlugin in disabled/read configurations, and tests verify write-mode rendering around an existing fenced code block.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a bunny with code in my burrow tonight,
Fenced blocks parse cleanly and render just right.
“Before” hops in, “After” hops through,
No Markdown errors disturb the view.
Sniff, test, rejoice— the editor is bright!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing markdown parsing for existing code blocks when withCodeBlocks is false.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/determined-carson-71BwF

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Environment

Your preview environment is ready!

Resource Details
🌐 Preview URL https://metaculus-pr-4804-claude-determined-carson-71bwf-preview.mtcl.cc
📦 Docker Image ghcr.io/metaculus/metaculus:claude-determined-carson-71bwf-339d3b8
🗄️ PostgreSQL NeonDB branch preview/pr-4804-claude-determined-carson-71bwf
Redis Fly Redis mtc-redis-pr-4804-claude-determined-carson-71bwf

Details

  • Commit: 70fc8ffe1472c7e9e181dcda71bbb9e83be3dd1e
  • Branch: claude/determined-carson-71BwF
  • Fly App: metaculus-pr-4804-claude-determined-carson-71bwf

ℹ️ Preview Environment Info

Isolation:

  • PostgreSQL and Redis are fully isolated from production
  • Each PR gets its own database branch and Redis instance
  • Changes pushed to this PR will trigger a new deployment

Limitations:

  • Background workers and cron jobs are not deployed in preview environments
  • If you need to test background jobs, use Heroku staging environments

Cleanup:

  • This preview will be automatically destroyed when the PR is closed

@SylvainChevalier SylvainChevalier marked this pull request as ready for review July 13, 2026 16:19
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.

3 participants