Markdown Editor
This repo contains two React-based editors:
- A WYSIWYG Slate-based editor that edits rich text and calls an
onChange
callback with the modified Slate DOM and the CommonMark markdown serialization. - A TextArea-based markdown editor that edits markdown text and calls an
onChange
callback with the equivalent Slate DOM and the modified markdown text.
Using these editors you could allow people to either edit rich formatted text using markdown (and provide a WYSIWYG preview), or allow them to edit using a WYSIWYG editor and use markdown for persistence.
The editor is plugin-based and includes a formatting toolbar. Plugins are used to extend the core editor with support with new formatting functionality and/or new types of blocks.
This component is Apache-2 licensed Open Source. Contributors welcome!
Demo
Usage
npm install @accordproject/markdown-editor
import { SlateAsInputEditor } from '@accordproject/markdown-editor';
import List from '@accordproject/markdown-editor/dist/plugins/list';
import Video from '@accordproject/markdown-editor/dist/plugins/video';
const plugins = [List(), Video()];
function storeLocal(slateValue, markdown) {
// console.log(markdown);
localStorage.setItem('markdown-editor', markdown);
}
ReactDOM.render(<SlateAsInputEditor plugins={plugins} lockText={false} onChange={storeLocal}/>
, document.getElementById('root'));
Example
For an example React App see the ./examples/
folder.
A TextArea
containing CommonMark synchronized with a MarkdownEditor
component, rendered using Slate.
The code for the sample video
plugin used in the demo is here:
https://github.com/accordproject/markdown-editor/blob/master/src/plugins/video.js
Run npm start
and then navigate to: http://localhost:3001/examples
Available Scripts
In the project directory, you can run:
npm start
Runs the app in the development mode.
Open http://localhost:3001/examples to view it in the browser.
The page will reload if you make edits.
npm run build
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!