Skip to content

Conversation

@budet-b
Copy link

@budet-b budet-b commented Dec 16, 2025

Summary

This PR adds support for embedding React components directly inside markdown content using JSX-style syntax.

New Features

  • JSX-style component syntax - Embed React components in markdown using familiar syntax:
    • Self-closing:
    • With children: Content here
  • Props support - String ("value"), number ({42}), boolean ({true}), and shorthand boolean props
  • useMarkdownWithComponents hook - New hook that combines markdown parsing with React component rendering
  • ReactComponentRegistryProvider - Context provider for registering available components

Usage Example

import { ReactComponentRegistryProvider, useMarkdownWithComponents } from "react-native-marked";

const components = {
  Button: ({ props }) => <Pressable><Text>{props.label}</Text></Pressable>,
  InfoBox: ({ props, children }) => <View><Text>{children}</Text></View>,
};

const markdown = `
  # Hello
  <Button label="Get Started" />
  <InfoBox title="Note">This is important</InfoBox>
`;

function App() {
  return (
    <ReactComponentRegistryProvider components={components}>
      <MarkdownContent />
    </ReactComponentRegistryProvider>
  );
}

Files Changed

File Description
src/lib/ReactComponentTokenizer.ts Tokenizer for parsing JSX-style components
src/lib/ReactComponentRegistry.tsx React context for component registration
src/hooks/useMarkdownWithComponents.tsx Main hook for markdown with components
src/index.ts Updated exports
README.md Documentation for the new feature

Test Plan

  • Added 15 unit tests for ReactComponentTokenizer
  • Added 9 unit tests for useMarkdownWithComponents hook
  • All 145 tests pass
  • Added example in examples/react-native-marked-sample/
  • Manual testing with example app

Preview

image

@gmsgowtham gmsgowtham self-assigned this Dec 16, 2025
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