1.5.4 • Published 7 years ago

react-marked-editor v1.5.4

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

react-marked-editor

A markdown editor written by React

version

The editor is powered by CodeMirror, and the markdown transcoder is powered by marked

Installation

$ npm install react-marked-editor

Usage

Firstly, add styled-jsx/babel to plugins in your babel configuration:

{
  "plugins": [
    "styled-jsx/babel"
  ]
}

Next, add font-awesome less/css files and font files to your project, and add some loaders to your webpack configuration:

{
    test: /\.less$/,
    loader: 'style-loader!css-loader!less-loader'
},
{
    test: /\.(woff|woff2|svg|eot|ttf)\??.*$/,
    loader: 'file-loader?name=[name].[ext]'
}

Add font-awesome less/css file import to your entry code:

import './path/to/font-awesome.(less|css)';

Finally, use the component in your code:

import ReactMarkedEditor from 'react-marked-editor';
//...
render() {
  return (
    <div>
      <ReactMarkedEditor initialMarkdown={md}/>
    </div>
  );
}

//show readonly markdown view
import { ReactMarkedView } from 'react-marked-editor';
//...
render() {
  return (
    <div>
      <ReactMarkedView markdown={md}/>
    </div>
  );
}

//get codeMirror instance
<ReactMarkedEditor ref={editor = this.editor = editor} {...otherProps}/>
//in somewhere
const codeMirror = this.editor.codeDoc;

API Doc

ReactMarkedEditor

propstypedetail
initialMarkdownstringthe initial markdown string to show
onChangefunctioneditor content change event, args -> (newValue)
markdownClassNamestringclassName pass to ReactMarkedView inside ReactMarkedEditor
markdownStyleobjectstyles object pass to ReactMarkedView inside ReactMarkedEditor
editorHeightnumberheight of editor (exclude toolbar)
hideToolbarbooleando not show the toolbar
styleobjectset styles to root element of ReactMarkedEditor
classNamestringset className to root element of ReactMarkedEditor
openLinkInBlankbooleanwhether open link in blank window/tab pass to ReactMarkedView
markedOptionsobjectoptions pass to marked
toolbarCustomButtonsarraycustom buttons add to toolbar, properties of child listed below ⬇︎
↳ titlestringthe title property of button element
↳ iconstringthe class name of Font Awesome icon
↳ onClickfunctionclick callback, args -> (codeMirror, event)

ReactMarkedView

propstypedetail
markdownstringthe initial markdown string to transcode
markdownClassstringthe className pass to root element to override the default style
markedOptionsobjectoptions pass to marked
styleobjectset styles to root element of ReactMarkedView
classNamestringset className to root element of ReactMarkedView
openLinkInBlankbooleanwhether open link in blank window/tab

Demo

Clone the repo

$ git clone https://github.com/lonord/react-marked-editor.git

Install dependencies

$ npm i

And run

$ npm start

License

MIT

1.5.4

7 years ago

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago