Skip to content

Commit 09ad7ba

Browse files
committed
feat: simplify example configs and add two-page structure
- Remove alias configurations from all examples (Vite, Webpack, Rollup, esbuild, Next.js) - Rely on pnpm workspace for automatic local package linking - Fix ESM/CJS compatibility issues: - Use dynamic import() for shiki in @react-code-view/core - Add explicit CJS exports in @react-code-view/unplugin webpack plugin - Fix package.json exports to correctly point to .mjs files for ESM - Add TypeScript declarations for .md imports in unplugin package - Refactor all examples with two-page structure: - Unplugin Demo page: showcases direct markdown import feature - Basic Usage page: demonstrates traditional CodeView usage - Update documentation to highlight unplugin as primary usage method - Remove InstallationPage from docs (consolidated into QuickStart)
1 parent d410af8 commit 09ad7ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2917
-1700
lines changed

README.md

Lines changed: 86 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
A React component library for rendering code with **live preview** and syntax highlighting.
88

9+
**✨ Highlight:** Import `.md` files as React components - write markdown, get interactive demos instantly!
10+
911
[Docs](https://react-code-view-rsuite.vercel.app/)
1012

1113
## ✨ Features
1214

15+
- 📝 **Native Markdown Parsing** - Import `.md` files and render embedded code blocks as interactive components
1316
- 🎨 **Live Preview** - Execute and preview React code in real-time
1417
- ✏️ **Editable Code** - Built-in code editor with syntax highlighting
15-
- 📝 **Native Markdown Parsing** - Parse and render markdown with embedded code blocks at runtime
1618
- 🔌 **Universal Plugin** - Works with Webpack, Vite, Rollup, esbuild, and Rspack
1719
- 🎯 **TypeScript** - Full TypeScript support out of the box
1820
- 📦 **Tree-shakeable** - Import only what you need
@@ -38,69 +40,96 @@ yarn add react-code-view
3840

3941
## 🚀 Quick Start
4042

41-
### Basic Code Preview
42-
43-
```tsx
44-
import CodeView from 'react-code-view';
45-
import 'react-code-view/styles';
46-
47-
function App() {
48-
const code = `
49-
<button onClick={() => alert('Hello!')}>
50-
Click me
51-
</button>
52-
`.trim();
53-
54-
return (
55-
<CodeView
56-
language="jsx"
57-
editable
58-
renderPreview
59-
>
60-
{code}
61-
</CodeView>
62-
);
63-
}
64-
```
43+
### ⭐ Import Markdown as React Components
6544

66-
### Markdown with Code Blocks (New!)
45+
The most convenient way - configure once, use everywhere!
6746

68-
CodeView now supports **native markdown parsing** - no build configuration needed!
47+
**1. Configure your build tool** (Vite example):
6948

70-
```tsx
71-
import CodeView from 'react-code-view';
72-
import markdown from './example.md?raw'; // Import as raw text
49+
```js
50+
// vite.config.js
51+
import { defineConfig } from 'vite';
52+
import react from '@vitejs/plugin-react';
53+
import reactCodeView from '@react-code-view/unplugin/vite';
7354

74-
function App() {
75-
return (
76-
<CodeView dependencies={{ useState: React.useState }}>
77-
{markdown}
78-
</CodeView>
79-
);
80-
}
55+
export default defineConfig({
56+
plugins: [
57+
react(),
58+
reactCodeView() // That's it!
59+
]
60+
});
8161
```
8262

83-
Your markdown file (`example.md`):
63+
**2. Create your markdown file** (`demo.md`):
8464

8565
```markdown
86-
# Interactive Example
66+
# Interactive Counter
8767

8868
Here's a live counter component:
8969

9070
<!--start-code-->
9171
\`\`\`jsx
9272
function Counter() {
9373
const [count, setCount] = useState(0);
94-
return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
74+
return (
75+
<button onClick={() => setCount(count + 1)}>
76+
Clicked {count} times
77+
</button>
78+
);
9579
}
9680
render(<Counter />);
9781
\`\`\`
9882
<!--end-code-->
9983

100-
More markdown content here...
84+
The code above is **fully interactive**!
10185
```
10286

103-
The code blocks are automatically extracted and rendered as interactive components!
87+
**3. Import and use like any React component**:
88+
89+
```tsx
90+
import Demo from './demo.md';
91+
92+
function App() {
93+
return <Demo />;
94+
}
95+
```
96+
97+
**That's it!** 🎉 Your markdown is now a React component with:
98+
- ✅ Live, interactive code blocks
99+
- ✅ Automatic syntax highlighting
100+
- ✅ Type-safe imports
101+
- ✅ Full TypeScript support
102+
103+
### Alternative: Runtime Parsing (No Build Config)
104+
105+
If you prefer not to configure a build tool:
106+
107+
```tsx
108+
import CodeView from 'react-code-view';
109+
import markdown from './demo.md?raw';
110+
111+
<CodeView dependencies={{ useState: React.useState }}>
112+
{markdown}
113+
</CodeView>
114+
```
115+
116+
### Basic Code Preview
117+
118+
For simple code snippets without markdown:
119+
120+
```tsx
121+
import CodeView from 'react-code-view';
122+
123+
const code = `
124+
<button onClick={() => alert('Hello!')}>
125+
Click me
126+
</button>
127+
`;
128+
129+
<CodeView language="jsx" editable renderPreview>
130+
{code}
131+
</CodeView>
132+
```
104133

105134
## 📚 Packages
106135

@@ -117,36 +146,29 @@ This monorepo contains the following packages:
117146

118147
React Code View supports all major build tools through [unplugin](https://github.com/unjs/unplugin).
119148

120-
The plugin uses **native parseHTML** by default, generating CodeView components that parse markdown at runtime:
149+
Once configured, you can **import `.md` files as React components** - the most convenient way to create interactive documentation!
121150

122-
```js
123-
// vite.config.js
124-
import { defineConfig } from 'vite';
125-
import react from '@vitejs/plugin-react';
126-
import reactCodeView from '@react-code-view/unplugin/vite';
151+
**Why this is amazing:**
152+
- 📝 Write markdown files with code examples
153+
- 🎯 Import them like regular React components
154+
- ⚡ Get live, interactive demos automatically
155+
- 🔒 Full TypeScript support and type safety
156+
- 🎨 Pass props like `theme`, `dependencies`, etc.
127157

128-
export default defineConfig({
129-
plugins: [
130-
react(),
131-
reactCodeView() // Uses native parseHTML by default
132-
]
133-
});
134-
```
135-
136-
Then import markdown files directly:
158+
**Example:**
137159

138160
```tsx
139161
import Demo from './example.md';
140162

141-
<Demo dependencies={{ useState: React.useState }} theme="rcv-theme-default" />
163+
function App() {
164+
return (
165+
<div>
166+
<Demo theme="rcv-theme-dark" />
167+
</div>
168+
);
169+
}
142170
```
143171

144-
**Benefits:**
145-
- ✅ Consistent with runtime `parseHTML` behavior
146-
- ✅ Interactive code blocks automatically rendered
147-
- ✅ Smaller bundle size (no pre-rendered HTML)
148-
- ✅ Type-safe imports from build tools
149-
150172
### Vite
151173

152174
```js

docs/components/Sidebar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const Sidebar: React.FC = () => {
1313
title: 'Getting Started',
1414
items: [
1515
{ path: '/', label: 'Overview' },
16-
{ path: '/installation', label: 'Installation' },
1716
{ path: '/quick-start', label: 'Quick Start' },
1817
]
1918
},

docs/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Sidebar } from './components/Sidebar';
1111

1212
// Pages
1313
import { OverviewPage } from './pages/OverviewPage';
14-
import { InstallationPage } from './pages/InstallationPage';
1514
import { QuickStartPage } from './pages/QuickStartPage';
1615
import { ComponentsPage } from './pages/ComponentsPage';
1716
import { BuildToolsPage } from './pages/BuildToolsPage';
@@ -61,7 +60,6 @@ const App: React.FC = () => {
6160
<main className="docs-main">
6261
<Routes>
6362
<Route path="/" element={<OverviewPage theme={theme} />} />
64-
<Route path="/installation" element={<InstallationPage theme={theme} />} />
6563
<Route path="/quick-start" element={<QuickStartPage theme={theme} />} />
6664
<Route path="/components/:component" element={<ComponentsPage theme={theme} />} />
6765
<Route path="/components/use-code-execution" element={<UseCodeExecutionPage theme={theme} />} />

docs/pages/InstallationPage.tsx

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)