Skip to content

Conversation

@dhruvisompura
Copy link
Contributor

@dhruvisompura dhruvisompura commented Jan 7, 2026

Follow up to PR #11212 that explores being able to directly render React components from markdown as suggested by @seeM in this comment: #11212 (review)!

Right now we do Markdown → Tokens → HTML String → DOM, which means we're generating HTML strings and then parsing them back into the DOM. In this PR we now do Markdown → Tokens → React Elements. The main idea is to skip the intermediate HTML string step and work directly with React components. We use Marked to get the tokenized version of the markdown and then pass the tokens to a custom renderer which converts the tokens to the appropriate react component.

That said, there are still a few cases where we need HTML parsing. KaTeX (for LaTeX math) and our syntax highlighting both return HTML strings rather than tokens, so we still use safeSetInnerHtml for those and convert the resulting DOM to React via domToReact.tsx utility (this is pretty close to what we were doing prior to this change but we needed a parser that could better handle katex html unlike htmlParser.ts).

The TokenMarkdownRenderer class handles the token-to-React conversion, with custom components like KatexMath, SyntaxHighlightedCode, and RawHtml for the more complex rendering scenarios.

One benefit of this approach as mentioned by @seeM is allowing us to easily create/explore richer markdown output.

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

@:positron-notebooks

@dhruvisompura dhruvisompura changed the base branch from main to notebooks/change-markdown-renderer January 7, 2026 23:15
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks

readme  valid tags

@dhruvisompura dhruvisompura marked this pull request as ready for review January 8, 2026 18:32
seeM
seeM previously approved these changes Jan 8, 2026
Copy link
Contributor

@seeM seeM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look great! I'll take it for a spin locally tomorrow morning, haven't had a chance yet

@dhruvisompura dhruvisompura requested a review from nstrayer January 8, 2026 19:02
@dhruvisompura dhruvisompura changed the base branch from notebooks/change-markdown-renderer to main January 8, 2026 19:22
@dhruvisompura dhruvisompura dismissed seeM’s stale review January 8, 2026 19:22

The base branch was changed.

@dhruvisompura dhruvisompura force-pushed the notebooks/react-renderer-for-markdown branch from f36349b to c10334c Compare January 8, 2026 19:25
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