Markdown Editor React
Installation
$ npm install md-editor-react codemirror --save
MDEditor Usage
MDEditor is used for show editor with editing controlls and live preview
; ; ;; <MDEditor defaultValue="Hello World"/>
CodeMirror is dependancy so you have to import codemirror css file and gfm mode for syntax highlighitng.
MDEditor Props
props | type | default | description |
---|---|---|---|
delay |
number | 300 |
input delay for parsing markdown and show html preview |
fullScreen |
boolean | false |
enable fullscreen mode |
watchMode |
boolean | true |
show html view |
className |
string | class name applied in wrapper | |
options |
object | codemirror options | |
onChange |
function | editor value on chagne event handler | |
menuConfig |
list | add a menu items in menubar | |
defaultValue |
string | set editor initial value | |
parserOptions |
object | used marked markdown parser options |
MDPreview Usage
MDPreview is used for parse markdown and preview html
; ; <MDPreview value="markdown value" />
MDPreview Props
props | type | description |
---|---|---|
value |
string | markdown value to parse and displayed |
parserOptions |
object | used marked markdown parser options |
sanitizerOptions |
object | DOMPurify senitizer options |
Highlight code in html preview
for highlight code you can used highlightjs library.
how to use in MDEditor
;; ;; ;; <MDEditor defaultValue="Hello World" parserOptions= hljsvalue />
how to use in MDPreview
;; ;; <MDPreview value="markdown value" parserOptions= hljsvalue />
Add Menu Item in Editor
use menuConfig
props in MDEditor component
<MDEditor menuConfig= id: 'uniq_id' title: 'Menu Title' icon: <MenuIcon /> { /* write your code here */ } />
props | type | description |
---|---|---|
id |
string | uniq id |
title |
string | title of menu item |
icon |
string or component | icon display in menu bar |
position |
number | menu item position starting from 1 (divider count included) |
command |
function | trigger after menu button clicked. editor passed as argument you can modify editor value |
component |
component | a react component render after menu clicked. component has close() and editor props |
add divider in menu bar
<MDEditor menuConfig= divider: true />
Menu item component props
if you want to display model like table, link menu. just import and use MDModel component.
; PureComponent { superprops; thisstate = text: '' ; thisonClickSuccess = thisonClickSuccess; thisonChangeInput = thisonChangeInput; } { const name value = eventtarget; this; } { const text = thisstate; const editor close = thisprops; if text editor; ; } { const close = thisprops; const text = thisstate; return <MDModal visible closable header="Menu Header" onClose=close> <MDModalBody className="menu-modal"> <MDInput value=text name="text" onChange=thisonChangeInput /> </MDModalBody> <MDModalFooter onSuccess=thisonClickSuccess onCancel=close /> </MDModal> ; }
License
md-editor-react is MIT licensed.