A markdown editor with preview, implemented with React.js and TypeScript.
A markdown editor with preview, implemented with React.js and TypeScript.
A markdown editor with preview, implemented with React.js and TypeScript.
Migrate from @uiw/react-markdown-editor 4.x to 5.x.
npm i @uiw/react-markdown-editorOfficial document demo preview (中国镜像网站)
import React from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';
const mdStr = `# This is a H1 \n## This is a H2 \n###### This is a H6`;
const Dome = () => {
return (
{
}}
/>
)
};
export default Dome;import React, { useState } from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';
const mdStr = `# This is a H1 \n## This is a H2 \n###### This is a H6`;
export default function App() {
const [markdown, setMarkdown] = useState(mdStr);
return (
setMarkdown(value)}
/>
);
}This markdown preview sub-component is a direct export @uiw/react-markdown-preview component, API documentation, please check @uiw/react-markdown-preview.
import React from 'react';
import MarkdownEditor from '@uiw/react-markdown-editor';
const mdStr = `# This is a H1 \n## This is a H2 \n###### This is a H6`;
function App() {
return (
);
}
export default App;…Disable preview feature
import React from "react";
import MarkdownEditor from '@uiw/react-markdown-editor';
const Dome = () => (
);
export default Dome;Use examples in nextjs.
npm install next-remove-imports
npm install @uiw/react-markdown-editor// next.config.js
const removeImports = require('next-remove-imports')();
module.exports = removeImports({});import dynamic from 'next/dynamic';
import '@uiw/react-markdown-editor/markdown-editor.css';
import '@uiw/react-markdown-preview/markdown.css';
const MarkdownEditor = dynamic(
() => import("@uiw/react-markdown-editor").then((mod) => mod.default),
{ ssr: false }
);
function HomePage() {
return (
);
}
export default HomePage;By default, the dark-mode is automatically switched according to the system. If you need to switch manually, just set the data-color-mode="dark" parameter for html Element.
document.documentElement.setAttribute('data-color-mode', 'dark')
document.documentElement.setAttribute('data-color-mode', 'light')Inherit custom color variables by adding .wmde-markdown-var selector.
const Demo = () => {
return (
)
}value (string) - the raw markdown that will be converted to html (required)visible?: boolean - Shows a preview that will be converted to html.toolbars?: ICommand[] | string[] - Tool display settings.toolbarsMode?: ICommand[] | string[] - Tool display settings.onChange?:function(editor: IInstance, data: CodeMirror.EditorChange, value: string) - called when a change is madeonBlur?: function(editor: IInstance, event: Event) - event occurs when an object loses focusonPreviewMode?: (isHide: boolean) => void - Edit mode and preview mode switching eventpreviewProps - react-markdown options………npm run watch # Listen create type and .tsx files.
npm run start # Preview code example.
npm run docAs always, thanks to our amazing contributors!
Made with action-contributors.
Licensed under the MIT License.
No open issues yet, or sync has not completed.