2.2.12 • Published 11 months ago

react-markdown-editor-cm5 v2.2.12

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

react markdown editor

demo online

online demo

Installation

npm i react-markdown-editor-cm5
or
yarn add react-markdown-editor-cm5

Usage

basic usage

import MdEditor from 'react-markdown-editor-cm5';
import 'react-markdown-editor-cm5/lib/style.css';

function App() {
  return (
    <>
      <MdEditor initialValue=""></MdEditor>
    </>
  );
}

export default App;

Config editor by codemirror

Use codemirror mode, just need import codemirror mode plugins, like:

import 'codemirror/mode/gfm/gfm';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/mode/css/css';
import 'codemirror/mode/go/go';

set scroll bar style

import 'codemirror/addon/scroll/simplescrollbars';
import 'codemirror/addon/scroll/simplescrollbars.css';

// editor config
<MdEditor initialValue="" options={{ scrollbarStyle: 'overlay' }}></MdEditor>;

react-markdown-editor-cm5 preset some hint, you need import codemirror addon

// hint
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/hint/show-hint.css';

Search and replace, need import searchcursor.js

import 'codemirror/addon/search/searchcursor.js';

Scroll bar display matching markers, need import some addon and css

import 'codemirror/addon/scroll/annotatescrollbar.js';
import 'codemirror/addon/search/matchesonscrollbar.js';
import 'codemirror/addon/search/matchesonscrollbar.css';

Some other addons

import 'codemirror/addon/edit/matchbrackets'; // match brackets
import 'codemirror/addon/edit/matchtags'; // match html tags
import 'codemirror/addon/display/placeholder'; // placeholder, if you set options.placeholder, need import this addon
import 'codemirror/addon/selection/active-line'; // line light current line
import 'codemirror/addon/search/match-highlighter';

Code fold, if you need fold others mode, just import their addon from codemirror/addon/fold/...

// code fold
import 'codemirror/addon/fold/markdown-fold.js';
import 'codemirror/addon/fold/foldgutter.js';
import 'codemirror/addon/fold/foldgutter.css';

More usage visit codemirror.net

API

props

type toolbar = 'bold' | 'checkList'| 'clear'| 'codeBlock'| 'dateTime'| 'dividing'| 'emoji'| 'fullScreen'| 'header'| | 'htmlEntities'| 'humpCase'| 'image' | 'inlineCode'| 'italic'| 'link'| 'lowerCase'| 'orderedList'| 'quote'| 'redo'| 'undo'| 'sub'| 'super'| 'table'| 'theme'| 'through'| 'toggleEditor'| 'unOrderedList'| 'upperCase'

Options interface:

interface Options extends EditorConfiguration {
  singleCursorHeightPerLine?: boolean;
  languages?: string[];
}
nametypedefaultdescription
initialValuestringinitial value of editor
widthnumber | string'100%'width of editor
heightnumber800height of editor,
toolbarsArray\<toolbar>all of toolbarcustom toollbar item, if it's a empty array, editor will hide toolbar
toolBarHeightnumber34height editor toolbar
onSave(markdown?: string, toc?: string): voidcallback when editor save
onChange(markdown?: string, toc?: string): voidcallback when editor content change
uploadImageMethod(file: string | Blob, insertImageCallback: (fileName: string, imageUrl: string) => void): void;method of upload image
optionsOptionscodsmirror options

example of uploadImageMethod

No matter what your upload method is, you just need call insertImageCallback after your upload method, filename param is the title of image, the imageUrl is the image url after upload

function App() {
  const uploadImageMethod: uploadImageMethod = (file, insertImageCallback) => {
    const uploadApi = 'http://localhost:8080/upload';
    const formData = new FormData();
    formData.append('file', file);

    fetch(uploadApi, {
      method: 'POST',
      body: formData,
    })
      .then((response) => response.json())
      .then((data) => {
        const { imgName, imageUrl } = data;
        insertImageCallback(imgName, imageUrl);
      })
      .catch((error) => {
        console.error(error);
      });
  };

  return (
    <div style={{ padding: '50px' }}>
      <MdEditor uploadImageMethod={uploadImageMethod} />
    </div>
  );
}
export default App;

Features

headers

h1 Heading

h2 Heading

h3 Heading

h4 Heading

h5 Heading
h6 Heading

Footnotes

Footnote 1 link^first. Footnote 2 link^second. Inline footnote^Text of inline footnote definition. Duplicated footnote reference^second.

Tables

OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.

Right aligned columns

OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.

Left aligned columns

OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.

Center aligned columns

OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.

Emoji

You can type any emoji like this :smile: :smiley: :cry: :wink:

See full emoji list here.

Links

link text

link with title

Autoconverted link https://github.com/nodeca/pica

Images

Minion

ToDo List:

  • ToDos
    • Buy some salad
    • Brush teeth
    • Drink some water

Alert Area

:::success Yes :tada: :::

:::info This is a message :mega: :::

:::warning Watch out :zap: :::

:::danger Oh No! :fire: :::

Emphasis

This is bold text

This is italic text

Deleted text

lu~lala~

Superscript: 19^th^

Subscript: H~2~O

++Inserted text++

==Marked text==

Syntax highlighting

var foo = function (bar) {
  return bar++;
};

console.log(foo(5));

Blockquotes

Blockquotes can also be nested...

...by using additional greater-than signs right next to each other...

...or with spaces between arrows.

Lists

Unordered

  • Create a list by starting a line with +, -, or *
  • Sub-lists are made by indenting 2 spaces:
    • Marker character change forces new list start:
      • Ac tristique libero volutpat at
      • Facilisis in pretium nisl aliquet
      • Nulla volutpat aliquam velit
  • Very easy!

Ordered

  1. Lorem ipsum dolor sit amet
  2. Consectetur adipiscing elit
  3. Integer molestie lorem at massa

^first: Footnote can have markup and multiple paragraphs.

^second: Footnote text.

2.2.12

11 months ago

2.2.1

1 year ago

2.0.3

1 year ago

2.2.0

1 year ago

2.0.2

1 year ago

2.2.3

1 year ago

2.0.5

1 year ago

2.2.2

1 year ago

2.0.4

1 year ago

2.2.5

12 months ago

2.0.7

1 year ago

2.2.4

1 year ago

2.0.6

1 year ago

2.2.11

12 months ago

2.2.7

12 months ago

2.0.9

1 year ago

2.2.6

12 months ago

2.0.8

1 year ago

2.2.10

12 months ago

2.0.1

1 year ago

1.2.17

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.3

1 year ago

2.0.11

1 year ago

2.0.12

1 year ago

1.2.20

1 year ago

2.0.10

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.21

1 year ago

1.2.22

1 year ago

1.2.27

1 year ago

2.1.0

1 year ago

1.2.25

1 year ago

1.2.26

1 year ago

2.2.9

12 months ago

2.2.8

12 months ago

1.2.12

2 years ago

1.2.13

2 years ago

1.2.11

2 years ago

1.2.16

2 years ago

1.2.14

2 years ago

1.2.15

2 years ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago