Skip to content

Commit a5208eb

Browse files
committed
feat: add markdown preview component MarkdownEditor.Markdown.
1 parent 431a076 commit a5208eb

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ ReactDOM.render(<Dome />, document.getElementById('app'));
6464
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-markdown-editor-ybpce?file=/src/App.js)
6565

6666
```jsx
67-
import MarkdownEditor from '@uiw/react-markdown-editor';
68-
import { createRoot } from 'react-dom/client';
6967
import React, { useState } from 'react';
68+
import MarkdownEditor from '@uiw/react-markdown-editor';
7069

7170
function App() {
7271
const [markdown, setMarkdown] = useState("");
@@ -81,6 +80,23 @@ function App() {
8180
export default App;
8281
```
8382

83+
## Only Markdown Preview
84+
85+
This markdown preview sub-component is a direct export [`@uiw/react-markdown-preview`](https://github.com/uiwjs/react-markdown-preview) component, API documentation, please check [`@uiw/react-markdown-preview`](https://github.com/uiwjs/react-markdown-preview).
86+
87+
```jsx
88+
import React from 'react';
89+
import MarkdownEditor from '@uiw/react-markdown-editor';
90+
91+
function App() {
92+
return (
93+
<MarkdownEditor.Markdown source="# This is a H1 \n## This is a H2 \n###### This is a H6" />
94+
);
95+
}
96+
97+
export default App;
98+
```
99+
84100
## Custom Toolbars
85101

86102
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-markdown-editorcustom-toolbars-forked-r9ocu?fontsize=14&hidenavigation=1&theme=dark)
@@ -282,6 +298,12 @@ export declare const defaultCommands: {
282298
};
283299
export declare const getCommands: () => ICommand[];
284300
export declare const getModeCommands: () => ICommand[];
301+
302+
declare const MarkdownEditor: MarkdownEditorComponent;
303+
declare type MarkdownEditorComponent = React.FC<React.PropsWithRef<IMarkdownEditor>> & {
304+
Markdown: typeof MarkdownPreview;
305+
};
306+
export default MarkdownEditor;
285307
```
286308

287309
### Development

src/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@ export interface MarkdownEditorRef {
5252
preview: React.RefObject<HTMLDivElement> | null;
5353
}
5454

55-
export default React.forwardRef<MarkdownEditorRef, IMarkdownEditor>(MarkdownEditor);
55+
const MarkdownEditor: MarkdownEditorComponent = React.forwardRef<MarkdownEditorRef, IMarkdownEditor>(
56+
MarkdownEditorInternal,
57+
) as unknown as MarkdownEditorComponent;
58+
type MarkdownEditorComponent = React.FC<React.PropsWithRef<IMarkdownEditor>> & {
59+
Markdown: typeof MarkdownPreview;
60+
};
5661

57-
function MarkdownEditor(
62+
MarkdownEditor.Markdown = MarkdownPreview;
63+
64+
export default MarkdownEditor;
65+
66+
function MarkdownEditorInternal(
5867
props: IMarkdownEditor,
5968
ref?: ((instance: MarkdownEditorRef) => void) | React.RefObject<MarkdownEditorRef> | null,
6069
) {

0 commit comments

Comments
 (0)