a light-weight Markdown editor based on markdown-it and React
npm install rc-md2html
npm install rc-md2html --save
`
Props
| Property | Description | Type | default | Remarks |
| --- | --- | --- | --- | --- |
| value | markdown content | String | '' | |
| style | component container style | Object | {height: '100%'} | |
| config | component config | Object | {view: {...}, logger: {...}} | |
| config.view | component UI | Object | {menu: true, md: true, html: true} | |
| config.imageUrl | default image url | String | '' | |
| config.linkUrl | default link url | String | '' | |
| config.logger | logger in order to undo or redo | Object | {interval: 3000} | |
| onChange | emitting when editor has changed | Function | ({html, md}) => {} | |
API
$3
this api return a markdown content
$3
this api return a html text parsed by markdown-it
Basic Usage
`js
'use strict';
import React from 'react'
import ReactDOM from 'react-dom'
import MdEditor from 'rc-md2html'
const mock_content = "Hello.\n\n This is markdown.\n It is fun\n * Love it or leave it."
export default class Demo extends React.Component {
handleEditorChange ({html, md}) {
console.log('handleEditorChange', html, md)
}
render() {
return (
value={mock_content}
onChange={this.handleEditorChange}
/>
)
}
}
`
More Example
`js
'use strict';
import React from 'react'
import ReactDOM from 'react-dom'
import MdEditor from 'rc-md2html'
const mock_content = "Hello.\n\n This is markdown.\n It is fun\n * Love it or leave it."
export default class Demo extends React.Component {
mdEditor = null
handleEditorChange ({html, md}) {
console.log('handleEditorChange', html, md)
}
handleGetMdValue = () => {
this.mdEditor && alert(this.mdEditor.getMdValue())
}
handleGetHtmlValue = () => {
this.mdEditor && alert(this.mdEditor.getHtmlValue())
}
render() {
return (
ref={node => this.mdEditor = node}
value={mock_content}
style={{height: '400px'}}
config={{
view: {
menu: true,
md: true,
html: true
},
imageUrl: 'https://octodex.github.com/images/minion.png'
}}
onChange={this.handleEditorChange}
/>
)
}
}
``